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. :(

Regards.
-- 
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)
		{
			Gtk.Application.Init ();
			_gtkContainer = InitializeGTK ();
			RunGTK ();
			while (_gtkContainer.Handle == IntPtr.Zero) { } // wait for the gtk handle
			Console.WriteLine ("GTK up and running.\n");
			
			_mwfContainer = InitializeMWF ();
			RunMWF ();
			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 (System.Windows.Forms.Application.Run); 
			t.Start ();
			while (!t.IsAlive) {};
		}
		
		private static void RunGTK ()
		{			
			Thread t = new Thread (Gtk.Application.Run); 
			t.Start ();
			while (!t.IsAlive) {};
		}

		private static Container InitializeGTK ()
		{
			Gtk.Window gtkWindow = new Gtk.Window ("Title");
			gtkWindow.ShowAll ();
			
			return gtkWindow;
		}
		
		private static Control InitializeMWF ()
		{
			Control mwfContainer = new Panel ();
			mwfContainer.Click += delegate { MessageBox.Show ("Panel clicked"); };
			mwfContainer.Controls.Add (new System.Windows.Forms.Button ());
			mwfContainer.BackColor = System.Drawing.Color.Yellow;
			mwfContainer.Size = new System.Drawing.Size (200, 200);
			mwfContainer.CreateControl ();

			return mwfContainer;
		}
	}
}
_______________________________________________
Mono-winforms-list maillist  -  Mono-winforms-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-winforms-list

Reply via email to