好的,我是 C# 的新手,但我需要创建一个简单的 GUI,但我没有 Visual Studio(我使用 Geany 和 Mono)。
问题是,当我尝试使用 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());
}
}
我在尝试编译时遇到了这些错误:
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
我下载了两个 DLL,但我不知道下一步该做什么。 代码链接:http://www.informit.com/articles/article.aspx?p=27316
最佳答案
您正在使用 Mono 不包含的 Microsoft WinForms UI 库。
您需要使用 Mono-compatible UI library ,例如 GTK#。
您还可以使用 Mono port of WinForms .
关于c# - 没有 Visual Studio 的 C# 中的 GUI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8466753/