On 7/28/07, Valentin Sawadski <[EMAIL PROTECTED]> wrote: > Hi, > > On Sat, 2007-07-28 at 00:38 +0300, Ivan N. Zlatev wrote: > > I have been trying to parent a MWF control in a GTK Container > > unsuccessfully. I have attached the result of my hackings, which > > doesn't crash, but doesn't seem to show the MWF control properly. > > > > Anyone care to help me out figure what's wrong and how to make this > > work? I really need this working in order to integrate the GSoC > > WinForms designer in MonoDevelop. :( > > I haven't got much experience with this kind of stuff, but at first > glance it looks like your control is being created at a different thread > than the one on which System.Windows.Forms.Application.Run is being > invoked on. > > Doesn't it needed to be created in the same thread because > System.Windows.Forms.Application.Run creates the message pumps only on > its current thread? >
Absolutely true. I have overlooked that and infact it seems to work very well now! Thanks! I have attached the updated code in case someone ever finds it useful for something. -- Ivan N. Zlatev Web: http://www.i-nZ.net "It's all some kind of whacked out conspiracy."
using System; using Gtk; using Gdk; using System.Windows.Forms; using System.Drawing; using System.Threading; namespace mwfingtk { class MainClass { private static Container _gtkContainer; private static Control _mwfContainer; public static void Main (string[] args) { RunGTK (); while (_gtkContainer == null) {} while (_gtkContainer.Handle == IntPtr.Zero) { } // wait for the gtk handle Console.WriteLine ("GTK up and running.\n"); RunMWF (); while (_mwfContainer == null) {} while (!_mwfContainer.IsHandleCreated) { } // wait for the mwf handle Console.WriteLine ("MWF up and running.\n"); Gtk.Application.Invoke ( delegate { Gdk.Window window = Gdk.Window.ForeignNew ((uint) _mwfContainer.Handle); window.Reparent (_gtkContainer.GdkWindow, 0, 0); window.Show (); Console.WriteLine ("Parenting complete.\n"); } ); } private static void RunMWF () { Thread t = new Thread (InitializeMWF); t.Start (); while (!t.IsAlive) {}; } private static void RunGTK () { Thread t = new Thread (InitializeGTK); t.Start (); while (!t.IsAlive) {}; } private static void InitializeGTK () { Gtk.Application.Init (); Gtk.Window gtkWindow = new Gtk.Window ("Title"); gtkWindow.ShowAll (); _gtkContainer = gtkWindow; Gtk.Application.Run (); } private static void InitializeMWF () { Control mwfContainer = new Panel (); mwfContainer.Click += delegate { System.Windows.Forms.Button b = new System.Windows.Forms.Button (); b.BackColor = System.Drawing.Color.Black; b.Top = 50; b.Left = 50; b.Click += delegate { b.Parent.Controls.Add (new System.Windows.Forms.ComboBox ()); }; _mwfContainer.Controls.Add (b); }; mwfContainer.Controls.Add (new System.Windows.Forms.Button ()); mwfContainer.BackColor = System.Drawing.Color.Yellow; mwfContainer.Size = new System.Drawing.Size (200, 200); mwfContainer.CreateControl (); _mwfContainer = mwfContainer; System.Windows.Forms.Application.Run (); } } }
_______________________________________________ Mono-winforms-list maillist - Mono-winforms-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-winforms-list