SnackerSWE
SnackerSWE

Reputation: 659

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).

The problem is, when I tried the following code that I found by 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. Link to the code: http://www.informit.com/articles/article.aspx?p=27316

Upvotes: 3

Views: 3311

Answers (2)

aleroot
aleroot

Reputation: 72636

You are using WinForm on mono, maybe will be better use GTK#, however if you want use WinForms on mono it is possible. Take a look at this documentation for more information .

You have to use gmcs in this way to compile your program :

gmcs Program.cs -r:System.Windows.Forms.dll

Upvotes: 4

SLaks
SLaks

Reputation: 887509

You're using the Microsoft WinForms UI library, which Mono does not include.

You need to use a Mono-compatible UI library, such as GTK#.
You can also use the Mono port of WinForms.

Upvotes: 5

Related Questions