c# - 没有 Visual Studio 的 C# 中的 GUI

标签 c# user-interface mono

好的,我是 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/

相关文章:

c# - List.Foreach(Delegate) 是在 Mono 中实现的吗?

c# - 是否有适用于 Mono 的 ILMerge 等效工具?

c# - C#/。NET-记录正在播放的当前音频

c# - 无法转换类型为 'WhereListIterator` 的对象 1[Web.Model.Appointment ]' to type ' Web.Model.Appointment'

user-interface - PyQt4将焦点赋予Widget,因为它由MainWindow调用并设置为CentralWidget?

java - 禁用时如何阻止 JButton 变灰?

c# - FromCurrentSynchronizationContext,我错过了什么吗?

macos - 在 OS X 上从单声道打印

c# - Visual Studio 2010 认为它处于 Debug模式(但它设置为 Release模式)

c# - 将 OnClick 事件附加到现有 JavaScript 按钮