WinForms在MonoDevelop中的应用
我刚刚安装了新的MonoDevelop Windows beta版,但在尝试创建C#Windows应用程序时,唯一的选择是GTK。既然Mono支持WinForms,为什么这不是MonoDevelop中的一个选项。我不希望在我的应用程序中有GTK依赖项。尽管自版本2.0以来,mono支持Winforms,但Winforms设计器在MonoDevelop中还不可用,这可能是MonoDevelop中缺少Winforms项目的原因WinForms在MonoDevelop中的应用,winforms,mono,monodevelop,Winforms,Mono,Monodevelop,我刚刚安装了新的MonoDevelop Windows beta版,但在尝试创建C#Windows应用程序时,唯一的选择是GTK。既然Mono支持WinForms,为什么这不是MonoDevelop中的一个选项。我不希望在我的应用程序中有GTK依赖项。尽管自版本2.0以来,mono支持Winforms,但Winforms设计器在MonoDevelop中还不可用,这可能是MonoDevelop中缺少Winforms项目的原因 另外,您应该将mono对winforms的支持看作是将现有winfor
另外,您应该将mono对winforms的支持看作是将现有winforms应用程序移植到linux的一种方式。如果你想从头开始制作一个跨平台的应用程序,你应该使用GTK#尽管没有WinForms项目模板,但你可以在MD运行的任何平台上用MD编写WinForms应用程序
只需创建一个新的空C#项目并添加对System.Windows.Forms的引用,然后编写代码,构建并运行。虽然MD中没有Winforms designer,但是您可以完成Winforms类型的代码。很抱歉,我最近尝试过这么做。虽然MonoDevelop不提供GUI设计器,但正如mhutch指出的那样,您确实可以手工编写Winforms。事情是这样的:
- 创建一个新的空C#项目
- 添加对System.Windows.Forms的引用
- 创建一个新的空C#文件:
using System;
using System.Windows.Forms;
namespace HelloForms
{
public class MainForm: Form
{
Label label1 = new Label();
public MainForm ()
{
this.SuspendLayout();
// Initialize your components here
this.label1.Text = "Hello, World!";
this.Controls.Add(label1);
this.ResumeLayout();
this.Name = "MainForm Name.";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "MainForm Title!";
}
}
public class Program
{
public static void Main(string[] args) {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm ());
}
}
}
通过向MainForm的构造函数中添加组件来扩展表单。是的,但这不是重点,我只是想使用MonoDevelop…有很多原因。我们使用System.Windows.Forms命名空间,因为我们已经构建了UI。对于UI中的其他工作,我们使用SharpDevelop,然后在MD中编码。您还必须添加对系统的引用