Duxducis
Duxducis

Reputation: 457

Why is Winforms in Mono not opening any window?

I'm trying to use Winforms for a simple application on my Mac in Mono C#, so far I've tested this code

using System;
using System.Drawing;
using System.Windows.Forms;

public class HelloWorld : Form
{
    static public void Main ()
    {
        Application.Run (new HelloWorld ());
    }

    public HelloWorld ()
    {
        Button b = new Button ();
        b.Text = "Click Me!";
        b.Click += new EventHandler (Button_Click);
        Controls.Add (b);
    }

    private void Button_Click (object sender, EventArgs e)
    {
        MessageBox.Show ("Button Clicked!");
    }
}

But no window is opening when I test it, any help? I think my question is specific to Mono.

Upvotes: 6

Views: 3260

Answers (2)

Pati K
Pati K

Reputation: 139

I just had the same problem. Not with Mono but with WinForms. For me the solution was:

  1. Remove bin and obj directories from WinForms project.
  2. Remove .vs directory (I was using Visual Studio).

Those above helped me. Of course I had to input any setting again, but at least I could use the application again.

Upvotes: 0

George Dima
George Dima

Reputation: 2787

i have the same issue, running os x mavericks + mono 3.2.3 .

i built the demos from here : http://mono-project.com/Mono_Basics , the first two worked (console+gtk) but the third (dotnet) does nothing when i run it from Terminal, doesn't throw any error, i only makes cpu load, but no window is shown...

in the end , i found the solution, on the first dotnet run, it takes about 1 minute until the window shows, on the next run it's instant. when i was testing, i was killing the process after 5-10 seconds, so that's why i didn't worked for me on first try...

Upvotes: 7

Related Questions