[英]GUI in C# without Visual Studio
Okay, I'm a newbie in C# but I need to create a simple GUI, but I don't have Visual Studio (I use Geany and Mono). 好吧,我是C#的新手,但我需要创建一个简单的GUI,但我没有Visual Studio(我使用Geany和Mono)。
The problem is, when I tried the following code that I found by Google: 问题是,当我尝试使用Google发现的以下代码时:
using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
public class FirstForm : Form
{
private Container components;
private Label howdyLabel;
public FirstForm()
{
InitializeComponent();
}
private void InitializeComponent()
{
components = new Container ();
howdyLabel = new Label ();
howdyLabel.Location = new Point (12, 116);
howdyLabel.Text = "Howdy, Partner!";
howdyLabel.Size = new Size (267, 40);
howdyLabel.AutoSize = true;
howdyLabel.Font = new Font (
"Microsoft Sans Serif",
26, System.
Drawing.FontStyle.Bold);
howdyLabel.TabIndex = 0;
howdyLabel.Anchor = AnchorStyles.None;
howdyLabel.TextAlign = ContentAlignment.MiddleCenter;
Text = "First Form";
Controls.Add (howdyLabel);
}
public static void Main()
{
Application.Run(new FirstForm());
}
}
I just get these errors when trying to compile: 我在尝试编译时遇到这些错误:
C:\C#\test2.cs(2,14): error CS0234: The type or namespace name 'Windows' does not exist in the namespace 'System'. Are you missing an assembly reference?
C:\C#\test2.cs(4,14): error CS0234: The type or namespace name 'Drawing' does not exist in the namespace 'System'. Are you missing an assembly reference?
C:\C#\test2.cs(9,11): error CS0234: The type or namespace name 'Label' could not be found. Are you missing a using directive or an assembly reference?
Compilation failed: 3 error(s), 0 warnings
I downloaded both DLL's, but I don't know what to do next. 我下载了两个DLL,但我不知道接下来该做什么。 Link to the code: http://www.informit.com/articles/article.aspx?p=27316
链接到代码: http : //www.informit.com/articles/article.aspx?p = 27316
You're using the Microsoft WinForms UI library, which Mono does not include. 您使用的是Microsoft WinForms UI库,Mono不包含该库。
You need to use a Mono-compatible UI library , such as GTK#. 您需要使用与Mono兼容的UI库 ,例如GTK#。
You can also use the Mono port of WinForms . 您还可以使用WinForms的Mono端口 。
You are using WinForm on mono, maybe will be better use GTK#, however if you want use WinForms on mono it is possible. 你在单声道上使用WinForm,也许会更好地使用GTK#,但是如果你想在单声道上使用WinForms它是可能的。 Take a look at this documentation for more information .
有关更多信息,请查看此文档。
You have to use gmcs
in this way to compile your program : 你必须以这种方式使用
gmcs
来编译你的程序:
gmcs Program.cs -r:System.Windows.Forms.dll
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.