学习 monodevelop 并且无法显示消息框
我正在 monodevelop 工作并学习 c#.... 我试图显示一个消息框,但无法使其正常运行...
这是我的代码:
using System;
using Gtk;
using GtkSharp;
public partial class MainWindow : Gtk.Window
{
public MainWindow () : base(Gtk.WindowType.Toplevel)
{
Build ();
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
protected virtual void OnButton11ResizeChecked (object sender, System.EventArgs e)
{
System.Windows.Forms.MessageBox.Show("Hello World Again!!");
}
}
我缺少什么?
I am working in monodevelop and learning c#....
I am trying to get a message box to appear but I can't get it to function correctly ...
Here is my code:
using System;
using Gtk;
using GtkSharp;
public partial class MainWindow : Gtk.Window
{
public MainWindow () : base(Gtk.WindowType.Toplevel)
{
Build ();
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
protected virtual void OnButton11ResizeChecked (object sender, System.EventArgs e)
{
System.Windows.Forms.MessageBox.Show("Hello World Again!!");
}
}
What am i missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能混合使用 GTK# 和 System.Windows.Forms UI 工具包。您需要使用 GTK 对话框,如下所示:
另请参阅 这个问题。
You cannot mix the GTK# and System.Windows.Forms UI toolkits. You need to use a GTK dialog, something like this:
See also this question.
您正在引用 GTK,它是 Mono 中捆绑的图形工具包,但正在尝试使用 Windows.Forms,尽管 Windows.Forms 也包含在 Mono 中,但它是一个不同的工具包:
System.Windows.Forms: 这是工具包在 Windows 中使用时,Mono 上的实现“模拟”了该控件在 Mono 运行的平台下的绘制和行为方式。
Gtk:这是许多开源应用程序(Firefox、Pidgin 等)中使用的工具包,GTKSharp 只是同一库的实现,但暴露于 mono 上可用的 .Net 语言,尽管您可以使用它也可以直接使用 Visual Studio 或 Microsoft 编译器。
所以总结一下,正如迈克所说,你不能同时使用它们,你必须选择其中之一。如果您刚刚学习 .Net,我强烈建议您学习 GTK 而不是 Windows Forms。 Windows 窗体是一种糟糕且基本的工具包,很快您就会发现您需要从第三方学习新的 API 来完成 Windows 窗体无法完成的操作(DevExpress、Infragistics),并且 Gtk 可以轻松扩展和根据您的需要进行调整。
You are referencing GTK which is the bundled graphical toolkit in mono but are trying to use Windows.Forms which, although included in mono too, is a different toolkit:
System.Windows.Forms: This is the toolkit used in windows, the implementation on mono "emulates" how this controls are drawn and behave under platforms that mono runs on.
Gtk: This is a toolkit used in many OpenSource applications (Firefox, Pidgin, etc) and GTKSharp is simply the implementation of this same library but exposed to the .Net languages available on mono although you could use it directly with Visual Studio or a Microsoft compiler too.
So summarizing, as Mike said, you cannot use them both, you have to choose either one. If you are just learning .Net I would greatly advice to learn GTK instead of Windows Forms. Windows forms is kind of poor and basic toolkit, and soon you'll find that you'll need to learn a new API from a third party to do stuff that windows forms cant do (DevExpress, Infragistics) and Gtk can be easily extended and adjusted to your needs.