views:

279

answers:

1

I am new to WinForms and I'm trying to use the WebBrowser control on GNU/Linux with Mono. It runs fine, but when I close the form I get strange warnings, and the application freezes when I try to create another form containing a WebBrowser.

In fact I can launch as many browsers as I wish, until I close one. Then if I create a new one the app freezes.

Here is a sample code:

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

 public class TestForm : Form
 {
   Button button = new Button();

   public TestForm()
   {
     button.Parent = this;
     button.Text = "Run browser";
     button.Click += button_Click;
   }

   [STAThread]
   public static void Main()
   {
     Application.Run(new TestForm());
   }

   public void button_Click(object sender, EventArgs e)
   {
     new MyBrowser("www.google.com").Show();
   }
 }

 class MyBrowser : Form
 {
   WebBrowser browser = new WebBrowser();

   public MyBrowser(string url)
   {
     browser.Parent = this;
     browser.Dock = DockStyle.Fill;
     browser.Navigate(url);
   }
 }

Here are the warnings I get:

 (essai.exe:9108): Gdk-WARNING **: GdkWindow 0x2800094 unexpectedly destroyed

 (essai.exe:9108): Gdk-WARNING **: GdkWindow 0x2800093 unexpectedly destroyed

 (essai.exe:9108): Gdk-WARNING **: GdkWindow 0x280007e unexpectedly destroyed

 (essai.exe:9108): Gdk-WARNING **: GdkWindow 0x280007d unexpectedly destroyed

 (essai.exe:9108): Gdk-WARNING **: GdkWindow 0x280001c unexpectedly destroyed

 (essai.exe:9108): Gdk-WARNING **: GdkWindow 0x280001b unexpectedly destroyed

 (essai.exe:9108): Gdk-WARNING **: GdkWindow 0x280001a unexpectedly destroyed


 (essai.exe:9108): Gdk-WARNING **: GdkWindow 0x2800016 unexpectedly destroyed

So my question is: what am I doing wrong? Is it possible that the problem comes from Mono?


Update: on Windows it works if I add [STAThread] before Main's definition.

+1  A: 

THe WebBrowser control from mono have some known issues. Try to find mwf-DESIGNER, in mono site.

RG