c# - Visual Studio 2010 中的 GTK#

标签 c# visual-studio-2010 mono gtk gtk#

我一整天都在尝试让 GTK# 在 Windows Server 2008 R2 x64 上的 Visual Studio 2010 中工作,这样我就可以开始编写不错的跨平台 GUI 应用程序,但我对 C# 有点陌生,而且我有麻烦的世界。

我为 Windows 安装了最新的 Mono,其中包括 GTK#。我还按照此处的指南安装了一个 Mono 2.10.8 配置文件作为我项目的目标框架:http://erictummers.wordpress.com/2012/01/25/target-mono-from-visual-studio/

我创建了一个新的 Windows 窗体应用程序并删除了对 Windows 窗体内容的引用并添加了对 GTK# 内容的引用,大致遵循此处的指南:http://jrwren.wrenfam.com/blog/2008/11/01/gtk-in-visual-studio-2008-on-vista-x64/

除了该指南中的引用之外,我还添加了对 gtk-dotnet 的引用。

这是我的应用程序的完整代码:

using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Linq;
using Gtk;

namespace GridToGo
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.Init();
            Window myWin = new Window("My first GTK# Application! ");
            myWin.Resize(200, 200);
            myWin.Destroyed += new EventHandler(myWin_Destroyed);
            Label myLabel = new Label();
            myLabel.Text = "Hello World!!!!";
            myWin.Add(myLabel);
            myWin.ShowAll();
            Application.Run();
        }

        static void myWin_Destroyed(object sender, EventArgs e)
        {
            Application.Quit();
        }
    }
}

当我尝试使用任何配置运行它时,出现以下异常:

System.TypeInitializationException was unhandled
  Message=The type initializer for 'Gtk.Application' threw an exception.
  Source=gtk-sharp
  TypeName=Gtk.Application
  StackTrace:
       at Gtk.Application.Init()
       at GridToGo.Program.Main() in F:\visual-studio\GridToGo\GridToGo\Program.cs:line 13
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.DllNotFoundException
       Message=Unable to load DLL 'glibsharpglue-2': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
       Source=glib-sharp
       TypeName=""
       StackTrace:
            at GLib.Thread.glibsharp_g_thread_supported()
            at GLib.Thread.get_Supported()
            at Gtk.Application..cctor()
       InnerException: 

我不知道如何让它找到那个 dll!我什至尝试将 4 个 DLL 副本复制到解决方案中的几乎每个文件夹中,名称如下:glibsharpglue-2 glibsharpglue-2.dll glibsharpglue-2 .o glibsharpglue-2.o.dll!我什至还尝试从 GTK 站点安装 GTK 一体化软件包并将其 bin 文件夹添加到我的系统路径,然后将相同的 4 个 dll 复制到该文件夹​​,但都没有成功。

对我的疯狂问题有什么建议吗?我觉得我在这里错过了一些大事。 >_<

最佳答案

我想通了! Windows 的 Mono 是完全没有必要的。 .NET 的 GTK# 正是我所需要的。对于将来想要为跨平台 GTK# 开发设置 Windows 环境的任何人,以下是我遵循的步骤:

  1. 按照此处的说明安装 Mono 项目目标:http://erictummers.wordpress.com/2012/01/25/target-mono-from-visual-studio/
  2. 从官方 Mono 下载站点安装适用于 .NET 的 GTK#。
  3. 在此处安装适用于 Windows 的 Glade/GTK+,sourceforge 项目:http://sourceforge.net/projects/gladewin32/
  4. 创建一个针对 Mono 的新 C# 项目。
  5. 从安装 GTK# for .NET 的地方引用项目所需的程序集。

关于c# - Visual Studio 2010 中的 GTK#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11337333/

相关文章:

c# - 缺少 using 指令或程序集引用 (ClientContext)

android - 我可以使用 XAML 在 Xamarin.Forms 中设计 UI 吗

c# - 在 Linux 下是否有一种简单的方法来实现类似于 C++ 中的 GC.GetTotalMemory 的函数?

c# - 局部变量与静态变量内存和性能

c# - vs2010 beta 2 下的 CS0120 错误 - 需要对象引用

c# - 等待并返回给调用者

wpf - 如何使用 List(Of T) 作为 WPF DataGrid 的 Itemssource?

c# - 可选引用文献类型

c# - .net 中是否有任何免费的 LPR(车牌识别器)软件?