2009-06-06 Carlos Alberto Cortez <calberto.cortez@gmail.com>
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / ControlTest.cs
index ddef7e15c5c348f91fe4f76793d93f534def3e13..a02b45fd1a1bab45469b49ee1f867ca9c2b9184e 100644 (file)
@@ -3,11 +3,12 @@
 //
 // Authors:
 //      Ritvik Mayank (mritvik@novell.com)
+//             Stefan Noack (noackstefan@googlemail.com)
 //
 
 using System;
 using System.Collections;
-using InvalidEnumArgumentException = System.ComponentModel.InvalidEnumArgumentException;
+using System.ComponentModel;
 using System.Drawing;
 using System.Reflection;
 using System.Runtime.Remoting;
@@ -18,12 +19,514 @@ using System.Windows.Forms.Layout;
 #endif
 
 using NUnit.Framework;
+using CategoryAttribute = NUnit.Framework.CategoryAttribute;
 
 namespace MonoTests.System.Windows.Forms
 {
        [TestFixture]
-       public class ControlTest
+       public class ControlTest : TestHelper
        {
+               [Test] // .ctor ()
+               public void Constructor1 ()
+               {
+                       MockControl c = new MockControl ();
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "Height");
+                       Assert.AreEqual (0, c.Left, "Left");
+                       Assert.AreEqual (string.Empty, c.Name, "Name");
+                       Assert.IsNull (c.Parent, "Parent");
+                       Assert.AreEqual (string.Empty, c.Text, "#A:Text");
+                       Assert.AreEqual (0, c.Top, "Top");
+                       Assert.AreEqual (0, c.Width, "Width");
+               }
+
+               [Test] // .ctor (String)
+               public void Constructor2 ()
+               {
+                       MockControl c = new MockControl ((string) null);
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#A:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#A:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#A:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#A:Height");
+                       Assert.AreEqual (0, c.Left, "#A:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#A:Name");
+                       Assert.IsNull (c.Parent, "#A:Parent");
+                       Assert.AreEqual (string.Empty, c.Text, "#A:Text");
+                       Assert.AreEqual (0, c.Top, "#A:Top");
+                       Assert.AreEqual (0, c.Width, "#A:Width");
+
+                       c = new MockControl ("child");
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#B:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#B:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#B:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#B:Height");
+                       Assert.AreEqual (0, c.Left, "#B:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#B:Name");
+                       Assert.IsNull (c.Parent, "#B:Parent");
+                       Assert.AreEqual ("child", c.Text, "#B:Text");
+                       Assert.AreEqual (0, c.Top, "#B:Top");
+                       Assert.AreEqual (0, c.Width, "#B:Width");
+               }
+
+               [Test] // .ctor (Control, String)
+               public void Constructor3 ()
+               {
+                       Control parent = new Control ("parent");
+                       MockControl c = new MockControl ((Control) null, (string) null);
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#A:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#A:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#A:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#A:Height");
+                       Assert.AreEqual (0, c.Left, "#A:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#A:Name");
+                       Assert.IsNull (c.Parent, "#A:Parent");
+                       Assert.AreEqual (string.Empty, c.Text, "#A:Text");
+                       Assert.AreEqual (0, c.Top, "#A:Top");
+                       Assert.AreEqual (0, c.Width, "#A:Width");
+
+                       c = new MockControl ((Control) null, "child");
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#B:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#B:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#B:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#B:Height");
+                       Assert.AreEqual (0, c.Left, "#B:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#B:Name");
+                       Assert.IsNull (c.Parent, "#B:Parent");
+                       Assert.AreEqual ("child", c.Text, "#B:Text");
+                       Assert.AreEqual (0, c.Top, "#B:Top");
+                       Assert.AreEqual (0, c.Width, "#B:Width");
+
+                       c = new MockControl (parent, (string) null);
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#C:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#C:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#C:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#C:Height");
+                       Assert.AreEqual (0, c.Left, "#C:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#C:Name");
+                       Assert.AreSame (parent, c.Parent, "#C:Parent");
+                       Assert.AreEqual (string.Empty, c.Text, "#C:Text");
+                       Assert.AreEqual (0, c.Top, "#C:Top");
+                       Assert.AreEqual (0, c.Width, "#C:Width");
+
+                       c = new MockControl (parent, "child");
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#D:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#D:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#D:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#D:Height");
+                       Assert.AreEqual (0, c.Left, "#D:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#D:Name");
+                       Assert.AreSame (parent, c.Parent, "#D:Parent");
+                       Assert.AreEqual ("child", c.Text, "#D:Text");
+                       Assert.AreEqual (0, c.Top, "#D:Top");
+                       Assert.AreEqual (0, c.Width, "#D:Width");
+               }
+
+               [Test] // .ctor (String, Int32, Int32, Int32, Int32)
+               public void Constructor4 ()
+               {
+                       MockControl c = new MockControl ((string) null, 0, 0, 0, 0);
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#A:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#A:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#A:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#A:Height");
+                       Assert.AreEqual (0, c.Left, "#A:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#A:Name");
+                       Assert.IsNull (c.Parent, "#A:Parent");
+                       Assert.AreEqual (string.Empty, c.Text, "#A:Text");
+                       Assert.AreEqual (0, c.Top, "#A:Top");
+                       Assert.AreEqual (0, c.Width, "#A:Width");
+
+                       c = new MockControl ((string) null, 1, 0, 0, 0);
+
+                       Assert.AreEqual (1, c.OnLocationChangedCount, "#B:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#B:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#B:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#B:Height");
+                       Assert.AreEqual (1, c.Left, "#B:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#B:Name");
+                       Assert.IsNull (c.Parent, "#B:Parent");
+                       Assert.AreEqual (string.Empty, c.Text, "#B:Text");
+                       Assert.AreEqual (0, c.Top, "#B:Top");
+                       Assert.AreEqual (0, c.Width, "#B:Width");
+
+                       c = new MockControl ("child", 0, 1, 0, 0);
+
+                       Assert.AreEqual (1, c.OnLocationChangedCount, "#C:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#C:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#C:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#C:Height");
+                       Assert.AreEqual (0, c.Left, "#C:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#C:Name");
+                       Assert.IsNull (c.Parent, "#C:Parent");
+                       Assert.AreEqual ("child", c.Text, "#C:Text");
+                       Assert.AreEqual (1, c.Top, "#C:Top");
+                       Assert.AreEqual (0, c.Width, "#C:Width");
+
+                       c = new MockControl ("child", 0, 0, 1, 0);
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#D:OnLocationChangedCount");
+                       Assert.AreEqual (1, c.OnResizeCount, "#D:OnResizeCount");
+                       Assert.AreEqual (1, c.OnSizeChangedCount, "#D:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#D:Height");
+                       Assert.AreEqual (0, c.Left, "#D:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#D:Name");
+                       Assert.IsNull (c.Parent, "#D:Parent");
+                       Assert.AreEqual ("child", c.Text, "#D:Text");
+                       Assert.AreEqual (0, c.Top, "#D:Top");
+                       Assert.AreEqual (1, c.Width, "#D:Width");
+
+                       c = new MockControl ("child", 0, 0, 0, 1);
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#E:OnLocationChangedCount");
+                       Assert.AreEqual (1, c.OnResizeCount, "#E:OnResizeCount");
+                       Assert.AreEqual (1, c.OnSizeChangedCount, "#E:OnSizeChangedCount");
+                       Assert.AreEqual (1, c.Height, "#E:Height");
+                       Assert.AreEqual (0, c.Left, "#E:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#E:Name");
+                       Assert.IsNull (c.Parent, "#E:Parent");
+                       Assert.AreEqual ("child", c.Text, "#E:Text");
+                       Assert.AreEqual (0, c.Top, "#E:Top");
+                       Assert.AreEqual (0, c.Width, "#E:Width");
+
+                       c = new MockControl ("child", 1, 0, 1, 0);
+
+                       Assert.AreEqual (1, c.OnLocationChangedCount, "#F:OnLocationChangedCount");
+                       Assert.AreEqual (1, c.OnResizeCount, "#F:OnResizeCount");
+                       Assert.AreEqual (1, c.OnSizeChangedCount, "#F:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#F:Height");
+                       Assert.AreEqual (1, c.Left, "#F:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#F:Name");
+                       Assert.IsNull (c.Parent, "#F:Parent");
+                       Assert.AreEqual ("child", c.Text, "#F:Text");
+                       Assert.AreEqual (0, c.Top, "#F:Top");
+                       Assert.AreEqual (1, c.Width, "#F:Width");
+
+                       c = new MockControl ("child", 0, 1, 0, 1);
+
+                       Assert.AreEqual (1, c.OnLocationChangedCount, "#G:OnLocationChangedCount");
+                       Assert.AreEqual (1, c.OnResizeCount, "#G:OnResizeCount");
+                       Assert.AreEqual (1, c.OnSizeChangedCount, "#G:OnSizeChangedCount");
+                       Assert.AreEqual (1, c.Height, "#G:Height");
+                       Assert.AreEqual (0, c.Left, "#G:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#G:Name");
+                       Assert.IsNull (c.Parent, "#G:Parent");
+                       Assert.AreEqual ("child", c.Text, "#G:Text");
+                       Assert.AreEqual (1, c.Top, "#G:Top");
+                       Assert.AreEqual (0, c.Width, "#G:Width");
+               }
+
+               [Test] // .ctor (Control, String, Int32, Int32, Int32, Int32)
+               public void Constructor5 ()
+               {
+                       Control parent = new Control ("parent");
+                       MockControl c = new MockControl ((Control) null,
+                               (string) null, 0, 0, 0, 0);
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#A:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#A:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#A:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#A:Height");
+                       Assert.AreEqual (0, c.Left, "#A:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#A:Name");
+                       Assert.IsNull (c.Parent, "#A:Parent");
+                       Assert.AreEqual (string.Empty, c.Text, "#A:Text");
+                       Assert.AreEqual (0, c.Top, "#A:Top");
+                       Assert.AreEqual (0, c.Width, "#A:Width");
+
+                       c = new MockControl (parent, (string) null, 1, 0, 0, 0);
+
+                       Assert.AreEqual (1, c.OnLocationChangedCount, "#B:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#B:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#B:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#B:Height");
+                       Assert.AreEqual (1, c.Left, "#B:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#B:Name");
+                       Assert.AreSame (parent, c.Parent, "#B:Parent");
+                       Assert.AreEqual (string.Empty, c.Text, "#B:Text");
+                       Assert.AreEqual (0, c.Top, "#B:Top");
+                       Assert.AreEqual (0, c.Width, "#B:Width");
+
+                       c = new MockControl ((Control) null, "child", 0, 1, 0, 0);
+
+                       Assert.AreEqual (1, c.OnLocationChangedCount, "#C:OnLocationChangedCount");
+                       Assert.AreEqual (0, c.OnResizeCount, "#C:OnResizeCount");
+                       Assert.AreEqual (0, c.OnSizeChangedCount, "#C:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#C:Height");
+                       Assert.AreEqual (0, c.Left, "#C:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#C:Name");
+                       Assert.IsNull (c.Parent, "#C:Parent");
+                       Assert.AreEqual ("child", c.Text, "#C:Text");
+                       Assert.AreEqual (1, c.Top, "#C:Top");
+                       Assert.AreEqual (0, c.Width, "#C:Width");
+
+                       c = new MockControl (parent, "child", 0, 0, 1, 0);
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#D:OnLocationChangedCount");
+                       Assert.AreEqual (1, c.OnResizeCount, "#D:OnResizeCount");
+                       Assert.AreEqual (1, c.OnSizeChangedCount, "#D:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#D:Height");
+                       Assert.AreEqual (0, c.Left, "#D:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#D:Name");
+                       Assert.AreSame (parent, c.Parent, "#D:Parent");
+                       Assert.AreEqual ("child", c.Text, "#D:Text");
+                       Assert.AreEqual (0, c.Top, "#D:Top");
+                       Assert.AreEqual (1, c.Width, "#D:Width");
+
+                       c = new MockControl (parent, "child", 0, 0, 0, 1);
+
+                       Assert.AreEqual (0, c.OnLocationChangedCount, "#E:OnLocationChangedCount");
+                       Assert.AreEqual (1, c.OnResizeCount, "#E:OnResizeCount");
+                       Assert.AreEqual (1, c.OnSizeChangedCount, "#E:OnSizeChangedCount");
+                       Assert.AreEqual (1, c.Height, "#E:Height");
+                       Assert.AreEqual (0, c.Left, "#E:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#E:Name");
+                       Assert.AreSame (parent, c.Parent, "#E:Parent");
+                       Assert.AreEqual ("child", c.Text, "#E:Text");
+                       Assert.AreEqual (0, c.Top, "#E:Top");
+                       Assert.AreEqual (0, c.Width, "#E:Width");
+
+                       c = new MockControl (parent, "child", 1, 0, 1, 0);
+
+                       Assert.AreEqual (1, c.OnLocationChangedCount, "#F:OnLocationChangedCount");
+                       Assert.AreEqual (1, c.OnResizeCount, "#F:OnResizeCount");
+                       Assert.AreEqual (1, c.OnSizeChangedCount, "#F:OnSizeChangedCount");
+                       Assert.AreEqual (0, c.Height, "#F:Height");
+                       Assert.AreEqual (1, c.Left, "#F:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#F:Name");
+                       Assert.AreSame (parent, c.Parent, "#F:Parent");
+                       Assert.AreEqual ("child", c.Text, "#F:Text");
+                       Assert.AreEqual (0, c.Top, "#F:Top");
+                       Assert.AreEqual (1, c.Width, "#F:Width");
+
+                       c = new MockControl (parent, "child", 0, 1, 0, 1);
+
+                       Assert.AreEqual (1, c.OnLocationChangedCount, "#G:OnLocationChangedCount");
+                       Assert.AreEqual (1, c.OnResizeCount, "#G:OnResizeCount");
+                       Assert.AreEqual (1, c.OnSizeChangedCount, "#G:OnSizeChangedCount");
+                       Assert.AreEqual (1, c.Height, "#G:Height");
+                       Assert.AreEqual (0, c.Left, "#G:Left");
+                       Assert.AreEqual (string.Empty, c.Name, "#G:Name");
+                       Assert.AreSame (parent, c.Parent, "#G:Parent");
+                       Assert.AreEqual ("child", c.Text, "#G:Text");
+                       Assert.AreEqual (1, c.Top, "#G:Top");
+                       Assert.AreEqual (0, c.Width, "#G:Width");
+               }
+
+               [Test]
+               public void DisposeTest ()
+               {
+                       ControlDisposeTester control = new ControlDisposeTester ();
+                       control.Visible = true;
+                       control.Dispose ();
+
+                       try {
+                               control.CreateControl ();
+                       } catch (ObjectDisposedException ex) {
+                               Console.WriteLine (ex);
+                               Assert.Fail ("#1");
+                       }
+                       Assert.IsFalse (control.IsHandleCreated, "#2");
+
+                       // The control remains Visible until WM_DESTROY is received.
+                       Assert.IsTrue (control.Visible, "#3");
+
+                       try {
+                               control.InvokeCreateHandle ();
+                               Assert.Fail ("#4");
+                       } catch (ObjectDisposedException ex) {
+                               //Console.WriteLine (ex);
+                       }
+               }
+
+               private class ControlDisposeTester : Control
+               {
+                       public void InvokeCreateHandle ()
+                       {
+                               CreateHandle ();
+                       }
+               }
+#if NET_2_0
+               [Test]
+               public void AutoSizeTest ()
+               {
+                       ControlAutoSizeTester c = new ControlAutoSizeTester (new Size (23, 17), AutoSizeMode.GrowAndShrink);
+                       
+                       Form f = new Form();
+                       f.Size = new Size (200, 200);
+                       c.Parent = f;
+                       f.Show();
+                       
+                       Size s = new Size (42, 42);
+                       c.Size = s;
+                       
+                       Point l = new Point (10, 10);
+                       c.Location = l;
+                       
+                       //Check wether normal size setting is OK
+                       Assert.AreEqual (s, c.Size, "#S1");
+                       
+                       //Check wether size remains without GetPreferredSize implemented even when AutoSize turned on.
+                       c.AutoSize = true;
+                       f.PerformLayout();
+                       Assert.AreEqual (s, c.Size, "#S2");
+                       
+                       //Simulate a Control implementing GetPreferredSize
+                       c.UseCustomPrefSize = true;
+                       f.PerformLayout();
+                       
+                       //Check wether size shrinks to preferred size
+                       Assert.AreEqual (c.CustomPrefSize, c.Size, "#S3");
+                       //Check wether Location stays constant
+                       Assert.AreEqual (l, c.Location, "#L1");
+                       
+                       //Check wether Dock is respected
+                       c.Dock = DockStyle.Bottom;
+                       Assert.AreEqual (f.ClientSize.Width, c.Width, "#D1");
+                       
+                       //Check wether size shrinks to preferred size again
+                       c.Dock = DockStyle.None;
+                       Assert.AreEqual (c.CustomPrefSize, c.Size, "#S4");
+                       
+                       //Check wether Anchor is respected for adjusting Locatioon
+                       c.Anchor = AnchorStyles.Bottom;
+                       f.Height += 50;
+                       Assert.AreEqual (l.Y + 50, c.Top, "#A1");
+                       //Check wether size is still OK
+                       Assert.AreEqual (c.CustomPrefSize, c.Size, "#S5");
+                       
+                       
+                       //just tidy up
+                       c.Anchor = AnchorStyles.Top | AnchorStyles.Left;
+                       c.Location = l;
+                       
+                       //Check wether shrinking to zero is possible 
+                       c.CustomPrefSize = new Size (0, 0);
+                       f.PerformLayout();
+                       Assert.AreEqual (c.CustomPrefSize, c.Size, "#S6");
+                       
+                       //Check wether MinimumSize is honored
+                       c.MinimumSize = new Size (10, 12);
+                       c.CustomPrefSize = new Size (5, 5);
+                       f.PerformLayout();
+                       Assert.AreEqual (c.MinimumSize, c.Size, "#S7");
+                       c.MinimumSize = new Size (0, 0);
+                       
+                       //Check wether MaximumSize is honored
+                       c.MaximumSize = new Size (100, 120); 
+                       c.CustomPrefSize = new Size (500, 500);
+                       f.PerformLayout();
+                       Assert.AreEqual (c.MaximumSize, c.Size, "#S8");
+                       
+                       //Check wether shrinking does not happen when GrowOnly
+                       c.AutoSize = false;
+                       s = new Size (23, 23);
+                       c.Size = s;
+                       c.CustomPrefSize = new Size (5, 5);
+                       c.AutoSizeMode = AutoSizeMode.GrowOnly;
+                       c.AutoSize = true;
+                       f.PerformLayout();
+                       Assert.AreEqual (s, c.Size, "#S9");
+                       f.Close ();
+               }
+               
+               public class ControlAutoSizeTester : Control {
+                       
+
+                       public ControlAutoSizeTester (Size customPrefSize, AutoSizeMode autoSizeMode)
+                       {
+                               custom_prefsize = customPrefSize;
+                               AutoSizeMode = autoSizeMode;
+                       }
+                       
+                       public AutoSizeMode AutoSizeMode {
+                               set {
+                                       base.SetAutoSizeMode (value);
+                               }
+                       }
+
+                       private bool use_custom_prefsize = false;
+                       public bool UseCustomPrefSize {
+                               set {
+                                       use_custom_prefsize = value;
+                               }
+                       }
+                       
+                       private Size custom_prefsize;
+                       
+                       public Size CustomPrefSize {
+                               get {
+                                       return custom_prefsize;
+                               }
+                               set {
+                                       custom_prefsize = value;
+                               }
+                       }
+                       
+                       
+                       public override Size GetPreferredSize (Size proposedSize)
+                       {
+                               if (use_custom_prefsize) {
+                                       return custom_prefsize;
+                               } else {        
+                                       return base.GetPreferredSize(proposedSize);
+                               }
+                       }
+                       
+               }
+#endif
+               
+               [Test]
+               public void Bug82748 ()
+               {
+                       Form f = new Form ();
+                       f.ShowInTaskbar = false;
+                       
+                       Control c = new Control ();
+                       c.Size = new Size (100, 100);
+                       
+                       Control c2 = new Control ();
+                       c2.Size = c.Size;
+                       c2.Controls.Add (c);
+                       
+                       c.Anchor = AnchorStyles.Right;
+                       
+                       f.Controls.Add (c);
+                       
+                       f.Show ();
+                       
+                       Assert.AreEqual (0, c.Left, "A1");
+                       
+                       f.Close ();
+                       f.Dispose ();
+               }
+               
+               [Test]
+               public void InvokeTestParentHandle ()
+               {
+                       Control child, parent;
+                       
+                       parent = new Control ();
+                       child = new Control ();
+                       parent.Controls.Add (child);
+                       parent.Visible = true;
+                       parent.CreateControl ();
+                       child.Invoke (new CrossAppDomainDelegate (dummy)) ;
+               }
+               
+               public void dummy ()
+               {
+               }
+               
                public class ControlStylesTester : Control {
                        private WindowStyles style;
                        private WindowStyles ex_style;
@@ -152,6 +655,9 @@ namespace MonoTests.System.Windows.Forms
                        Control.ControlCollection c = new Control.ControlCollection (frm);
                        child.MdiParent = frm;
                        c.Add (child);
+                       
+                       child.Dispose ();
+                       frm.Dispose ();
                }
 
                [Test]
@@ -164,6 +670,9 @@ namespace MonoTests.System.Windows.Forms
                        Control.ControlCollection c = new Control.ControlCollection (frm);
                        //child.MdiParent = frm;
                        c.Add (child);
+                       
+                       child.Dispose ();
+                       frm.Dispose ();                 
                }
                
                [Test]
@@ -251,8 +760,9 @@ namespace MonoTests.System.Windows.Forms
                                overrides.Add("OnPaint");
                        }
                }
-               
+
                [Test]
+               [Ignore ("Can't find a reliable way to generate a paint message on Windows.")]
                public void EventStyleTest ()
                {
 #if NET_2_0
@@ -373,14 +883,17 @@ namespace MonoTests.System.Windows.Forms
                }
 
                [Test]
+               [Ignore ("Can't find a reliable way to generate a paint message on Windows.")]
                public void DoubleBufferTest ()
                {
                        DoubleBufferedForm f = new DoubleBufferedForm ();
+                       f.ShowInTaskbar = false;
                        f.Show ();
                        f.Refresh ();
                        
                        Assert.IsFalse (f.failed, "#01");
                        Assert.IsTrue (f.painted, "The control was never painted, so please check the test");
+                       f.Close ();
                }
 
                [Test]
@@ -506,20 +1019,69 @@ namespace MonoTests.System.Windows.Forms
                        Assert.IsFalse (c.Created, "A1");
                }
 
+               class CustomA11yEnabledControl : Control {
+                       public CustomA11yEnabledControl () : base() { }
+                       protected override AccessibleObject CreateAccessibilityInstance () { return new CustomAccessibleObject (this); }
+
+                       class CustomAccessibleObject : ControlAccessibleObject {
+                               public CustomAccessibleObject (CustomA11yEnabledControl control) : base(control) { }
+                               public override string Name { get { return "custom name"; } }
+                               public override string DefaultAction { get { return "custom default action"; } }
+                               public override string Description { get { return "custom description"; } }
+                               public override AccessibleRole Role { get { return AccessibleRole.Alert; } }
+                       }
+               }
+
                [Test]
-               [Category ("NotWorking")]
                public void CreatedAccessibilityTest ()
                {
-                       Control c = new Control ();
-                       Assert.IsFalse (c.Created, "A1");
+                       CustomA11yEnabledControl c = new CustomA11yEnabledControl ();
+                       Assert.IsFalse(c.Created, "A1");
 
-                       Helper.TestAccessibility(c, null, null, null, AccessibleRole.Default);
+                       // Tests default values
 
-                       Assert.IsTrue (c.Created, "A2");
+                       Assert.AreEqual (null, c.AccessibleDefaultActionDescription, "A2.0");
+                       Assert.IsFalse(c.IsHandleCreated, "A2.1");
 
-                       c.Dispose ();
+                       Assert.AreEqual (null, c.AccessibleDescription, "A3.0");
+                       Assert.IsFalse(c.IsHandleCreated, "A3.1");
+
+                       Assert.AreEqual (null, c.AccessibleName, "A4.0");
+                       Assert.IsFalse(c.IsHandleCreated, "A4.1");
+
+                       Assert.AreEqual (AccessibleRole.Default, c.AccessibleRole, "A5.0");
+                       Assert.IsFalse(c.IsHandleCreated, "A5.1");
+
+                       object o = c.AccessibilityObject;
+                       Assert.IsTrue(c.IsHandleCreated, "A6");
+
+                       // Tests to confirm that:
+                       // - calling Control.AccessibleXXXXX is not returning AccessibleObject.XXXXX
+                       // - Handle is not Created when calling Control.AccessibleXXXXX
+                       c = new CustomA11yEnabledControl ();
+
+                       string accessibleDefaultActionDescription = "default action description";
+                       c.AccessibleDefaultActionDescription = accessibleDefaultActionDescription;
+                       Assert.IsFalse (c.IsHandleCreated, "A7.0");
+                       Assert.AreEqual (accessibleDefaultActionDescription, c.AccessibleDefaultActionDescription, "A7.1");
+
+                       string accessibleDescription = "accessible description";
+                       c.AccessibleDescription = accessibleDescription;
+                       Assert.IsFalse (c.IsHandleCreated, "A8.0");
+                       Assert.AreEqual (accessibleDescription, c.AccessibleDescription, "A8.1");
 
-                       Assert.IsFalse (c.Created, "A3");
+                       string accessibleName = "accessible name";
+                       c.AccessibleName = accessibleName;
+                       Assert.IsFalse (c.IsHandleCreated, "A9.0");
+                       Assert.AreEqual (accessibleName, c.AccessibleName, "A9.1");
+
+                       AccessibleRole accessibleRole = AccessibleRole.Diagram;
+                       c.AccessibleRole = accessibleRole;
+                       Assert.AreEqual (accessibleRole, c.AccessibleRole, "A10.0");
+                       Assert.IsFalse (c.IsHandleCreated, "A10.1");
+
+                       c.Dispose ();
+                       Assert.IsFalse (c.Created, "A11");
                }
 
                [Test]
@@ -649,7 +1211,7 @@ namespace MonoTests.System.Windows.Forms
                        Assert.IsTrue(c.MinimumSize.IsEmpty);
 #endif
                        Assert.AreEqual (Keys.None, Control.ModifierKeys, "M1");
-                       Assert.IsFalse (Control.MousePosition.IsEmpty, "M2");
+                       Assert.IsTrue (Control.MousePosition.X >= 0 && Control.MousePosition.Y >= 0, "M2");
                        Assert.AreEqual (MouseButtons.None, Control.MouseButtons, "M3");
 
                        Assert.AreEqual("", c.Name, "N1");
@@ -734,6 +1296,8 @@ namespace MonoTests.System.Windows.Forms
 
                        Assert.AreEqual (f, c.TopLevelControl, "T3");
                        Assert.AreEqual (f, f.TopLevelControl, "T4");
+                       
+                       f.Dispose ();
                }
 
                [Test]
@@ -1000,6 +1564,192 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreEqual(40, r1.Height, "Scale2");
                }
 
+#if NET_2_0
+               [Test]
+               public void ScaleChildrenTest ()
+               {
+                       ScaleChildrenControl c = new ScaleChildrenControl ();
+                       Assert.AreEqual (true, c.PublicScaleChildren, "A1");
+               }
+               
+               private class ScaleChildrenControl : Control
+               {
+                       public bool PublicScaleChildren {
+                               get { return base.ScaleChildren; }
+                       }
+               }
+               
+               [Test]
+               public void ScaleControlTest ()
+               {
+                       ScaleControl c = new ScaleControl ();
+                       
+                       c.Location = new Point (5, 10);
+                       c.Size = new Size (15, 20);
+                       
+                       Assert.AreEqual (new Rectangle (5, 10, 15, 20), c.Bounds, "A1");
+
+                       c.PublicScaleControl (new SizeF (1.5f, 1.3f), BoundsSpecified.All);
+                       Assert.AreEqual (new Rectangle (8, 13, 22, 26), c.Bounds, "A2");
+
+                       c.PublicScaleControl (new SizeF (2f, 1.5f), BoundsSpecified.Location);
+                       Assert.AreEqual (new Rectangle (16, 20, 22, 26), c.Bounds, "A3");
+
+                       c.PublicScaleControl (new SizeF (1.5f, 2f), BoundsSpecified.Size);
+                       Assert.AreEqual (new Rectangle (16, 20, 33, 52), c.Bounds, "A4");
+
+                       c.PublicScaleControl (new SizeF (1.5f, 1.5f), BoundsSpecified.Width);
+                       Assert.AreEqual (new Rectangle (16, 20, 50, 52), c.Bounds, "A5");
+
+                       c.PublicScaleControl (new SizeF (1.5f, 1.3f), BoundsSpecified.None);
+                       Assert.AreEqual (new Rectangle (16, 20, 50, 52), c.Bounds, "A6");
+                       
+                       // Test with ScaleChildren
+                       c = new ScaleControl ();
+
+                       c.Location = new Point (5, 10);
+                       c.Size = new Size (50, 50);
+                       
+                       Control c2 = new Control ();
+                       c2.Location = new Point (15, 15);
+                       c2.Size = new Size (25, 25);
+                       c.Controls.Add (c2);
+
+                       Assert.AreEqual (new Rectangle (5, 10, 50, 50), c.Bounds, "B1");
+                       Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B2");
+
+                       c.scale_children = false;
+
+                       c.PublicScaleControl (new SizeF (2f, 2f), BoundsSpecified.All);
+                       Assert.AreEqual (new Rectangle (10, 20, 100, 100), c.Bounds, "B3");
+                       Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B4");
+
+                       c.scale_children = true;
+
+                       // Will not scale children in ScaleControl
+                       c.PublicScaleControl (new SizeF (2f, 2f), BoundsSpecified.All);
+                       Assert.AreEqual (new Rectangle (20, 40, 200, 200), c.Bounds, "B5");
+                       Assert.AreEqual (new Rectangle (15, 15, 25, 25), c2.Bounds, "B6");
+                       
+                       // Does scale children in Scale
+                       c.Scale (new SizeF (2f, 2f));
+                       Assert.AreEqual (new Rectangle (40, 80, 400, 400), c.Bounds, "B7");
+                       Assert.AreEqual (new Rectangle (30, 30, 50, 50), c2.Bounds, "B8");
+               }
+               
+               [Test]
+               public void GetScaledBoundsTest ()
+               {
+                       ScaleControl c = new ScaleControl ();
+                       
+                       Rectangle r = new Rectangle (10, 20, 30, 40);
+
+                       Assert.AreEqual (new Rectangle (20, 10, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A1");
+                       Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A2");
+                       Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A3");
+                       Assert.AreEqual (new Rectangle (10, 20, 30, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A4");
+                       Assert.AreEqual (new Rectangle (20, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A5");
+                       Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A6");
+                       
+                       c.PublicSetTopLevel (true);
+
+                       Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A7");
+                       Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A8");
+                       Assert.AreEqual (new Rectangle (10, 20, 60, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A9");
+                       Assert.AreEqual (new Rectangle (10, 20, 30, 20), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A10");
+                       Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A11");
+                       Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A12");
+
+                       c = new ScaleControl ();
+                       c.PublicSetStyle (ControlStyles.FixedHeight, true);
+                       c.PublicSetStyle (ControlStyles.FixedWidth, true);
+
+                       Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A13");
+                       Assert.AreEqual (new Rectangle (20, 10, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A14");
+                       Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A15");
+                       Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A16");
+                       Assert.AreEqual (new Rectangle (20, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A17");
+                       Assert.AreEqual (new Rectangle (10, 20, 30, 40), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A18");
+               }
+               
+               private class ScaleControl : Control
+               {
+                       public bool scale_children = true;
+                       
+                       public void PublicScaleControl (SizeF factor, BoundsSpecified specified)
+                       {
+                               base.ScaleControl (factor, specified);
+                       }
+
+                       public Rectangle PublicGetScaledBounds (Rectangle bounds, SizeF factor, BoundsSpecified specified)
+                       {
+                               return base.GetScaledBounds (bounds, factor, specified);
+                       }
+                       
+                       public void PublicSetStyle (ControlStyles flag, bool value)
+                       {
+                               base.SetStyle (flag, value);
+                       }
+                       
+                       public void PublicSetTopLevel (bool value)
+                       {
+                               base.SetTopLevel (value);
+                       }
+                       
+                       protected override bool ScaleChildren {
+                               get { return scale_children; }
+                       }
+               }
+#endif
+
+               [Test]  // Bug #347282
+               public void ScaleHierarchy ()
+               {
+                       Form f = new Form ();
+                       Panel p = new Panel ();
+                       Button b = new Button ();
+                       
+                       f.ClientSize = new Size (300, 300);
+
+                       f.Controls.Add (p);
+                       p.Controls.Add (b);
+                       
+                       f.AutoScaleBaseSize = new Size (3, 11);
+                       f.Show ();
+                       
+                       // Due to font differences, all we can guarantee is that
+                       // the button is larger that the default.
+                       Assert.IsTrue (b.Width > 75, "A1");
+                       Assert.IsTrue (b.Height > 23, "A2");
+                       
+                       f.Dispose ();
+               }
+               
+               class TestWindowTarget : IWindowTarget
+               {
+                       public void OnHandleChange (IntPtr newHandle) {
+                       }
+
+                       public void OnMessage (ref Message m) {
+                       }
+               }
+
+               [Test]
+               public void WindowTargetTest()
+               {
+                       Control c = new Control ();
+                       Assert.IsNotNull (c.WindowTarget, "WindowTarget1");
+                       c.WindowTarget = null;
+                       Assert.IsNull (c.WindowTarget, "WindowTarget2");
+
+                       IWindowTarget existing_target = c.WindowTarget;
+                       IWindowTarget new_target = new TestWindowTarget ();
+                       c.WindowTarget = new_target;
+                       Assert.AreSame (new_target, c.WindowTarget, "WindowTarget3");
+                       
+                       TestHelper.RemoveWarning (existing_target);
+               }
+
                [Test]
                public void TextTest()
                {
@@ -1078,99 +1828,6 @@ namespace MonoTests.System.Windows.Forms
                }
 
                [Test]
-               public void CreateHandleTest ()
-               {
-                       Control parent;
-                       Control child;
-
-                       parent = null;
-                       child = null;
-
-                       try {
-                               parent = new Control ();
-                               child = new Control ();
-
-                               parent.Visible = true;
-                               parent.Controls.Add (child);
-
-                               Assert.IsFalse (parent.IsHandleCreated, "CH1");
-                               Assert.IsFalse (child.IsHandleCreated, "CH2");
-
-                               parent.CreateControl ();
-                               Assert.IsNotNull (parent.Handle, "CH3");
-                               Assert.IsNotNull (child.Handle, "CH4");
-                               Assert.IsTrue (parent.IsHandleCreated, "CH5");
-                               Assert.IsTrue (child.IsHandleCreated, "CH6");
-                       } finally {
-                               if (parent != null)
-                                       parent.Dispose ();
-                               if (child != null)
-                                       child.Dispose ();
-                       }
-
-                       // Accessing Handle Property creates the handle
-                       try {
-                               parent = new Control ();
-                               parent.Visible = true;
-                               child = new Control ();
-                               parent.Controls.Add (child);
-                               Assert.IsFalse (parent.IsHandleCreated, "CH7");
-                               Assert.IsFalse (child.IsHandleCreated, "CH8");
-                               Assert.IsNotNull (parent.Handle, "CH9");
-                               Assert.IsTrue (parent.IsHandleCreated, "CH10");
-                               Assert.IsTrue (child.IsHandleCreated, "CH11");
-                       } finally {
-                               if (parent != null)
-                                       parent.Dispose ();
-                               if (child != null)
-                                       child.Dispose ();
-                       }
-               }
-
-               [Test]
-               [Category ("NotWorking")]
-               public void CreateHandleTest2 ()
-               {
-                       // This should eventually test all operations
-                       // that can be performed on a control (within
-                       // reason)
-                       Control c = new Control ();
-
-                       Assert.IsFalse (c.IsHandleCreated, "0");
-
-                       c.Width = 100;
-                       Assert.IsFalse (c.IsHandleCreated, "1");
-
-                       c.Height = 100;
-                       Assert.IsFalse (c.IsHandleCreated, "2");
-
-                       c.Name = "hi";
-                       Assert.IsFalse (c.IsHandleCreated, "3");
-
-                       c.Left = 5;
-                       Assert.IsFalse (c.IsHandleCreated, "5");
-
-                       c.Top = 5;
-                       Assert.IsFalse (c.IsHandleCreated, "6");
-
-                       c.Location = new Point (1, 1);
-                       Assert.IsFalse (c.IsHandleCreated, "7");
-
-                       c.Region = new Region ();
-                       Assert.IsFalse (c.IsHandleCreated, "8");
-
-                       c.Size = new Size (100, 100);
-                       Assert.IsFalse (c.IsHandleCreated, "9");
-
-                       c.Text = "bye";
-                       Assert.IsFalse (c.IsHandleCreated, "10");
-
-                       c.Visible = !c.Visible;
-                       Assert.IsFalse (c.IsHandleCreated, "11");
-               }
-
-               [Test]
-               [Category ("NotWorking")]
                public void IsHandleCreated_NotVisible ()
                {
                        Control c = new Control ();
@@ -1186,8 +1843,29 @@ namespace MonoTests.System.Windows.Forms
                        Assert.IsTrue (c.IsHandleCreated, "#2");
                        c.Visible = false;
                        Assert.IsTrue (c.IsHandleCreated, "#3");
+                       form.Close ();
+               }
+
+               class OnCreateControlTest : Control {
+                       public bool reached = false;
+                       protected override void OnCreateControl () {
+                               reached = true;
+                       }
+               }
+
+               [Test]
+               public void CreateControlVisibleTest ()
+               {
+                       OnCreateControlTest test = new OnCreateControlTest ();
+                       test.Visible = false;
+                       Assert.IsFalse (test.IsHandleCreated, "0");
+                       Assert.IsFalse (test.Visible, "1");
+                       test.Visible = true;
+                       Assert.IsTrue (test.Visible, "2");
+                       Assert.IsTrue (test.reached, "3");
                }
 
+
                [Test]
                public void CreateGraphicsTest ()
                {
@@ -1335,7 +2013,8 @@ namespace MonoTests.System.Windows.Forms
                [Test]
                public void GetChildAtPointTest ()
                {
-                       Control c = null, d = null, e = null;
+                       Control c = null, d = null;
+                       TransparentControl e = null;
 
                        try {
                                c = new Control ();
@@ -1347,7 +2026,7 @@ namespace MonoTests.System.Windows.Forms
                                d.SetBounds (10, 10, 40, 40);
                                c.Controls.Add (d);
 
-                               e = new Control ();
+                               e = new TransparentControl ();
                                e.Name = "e1";
                                e.SetBounds (55, 55, 10, 10);
 
@@ -1356,22 +2035,40 @@ namespace MonoTests.System.Windows.Forms
                                Assert.IsFalse (e.Name == l.Name, "Child2");
 
                                l = c.GetChildAtPoint (new Point (57, 57));
-                               Assert.IsNull (l, "Child3");
+                               Assert.AreEqual (null, l, "Child3");
 
                                l = c.GetChildAtPoint (new Point (10, 10));
                                Assert.AreEqual (d.Name, l.Name, "Child4");
 
                                // GetChildAtPointSkip is not implemented and the following test is breaking for Net_2_0 profile
-//                             #if NET_2_0
-//                                     c.Controls.Add (e);
-//                                     e.Visible = false;
-//                                     l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
-//                                     Assert.IsNull (l, "Child5");
-
-//                                     e.Visible = true;
-//                                     l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
-//                                     Assert.AreSame (e.Name, l.Name, "Child6");
-//                             #endif // NET_2_0
+#if NET_2_0
+                               c.Controls.Add (e);
+                               e.Visible = false;
+                               l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
+                               Assert.IsNull (l, "Child5");
+
+                               e.Visible = true;
+                               l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Invisible);
+                               Assert.AreSame (e.Name, l.Name, "Child6");
+
+                               e.Enabled = false;
+                               l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Disabled);
+                               Assert.IsNull (l, "Child7");
+
+                               e.Enabled = true;
+                               l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Disabled);
+                               Assert.AreSame (e.Name, l.Name, "Child8");
+
+                               
+                               e.BackColor = Color.Transparent;
+                               l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Transparent);
+                               Assert.IsNull (l, "Child9");
+
+                               e.BackColor = Color.Green;
+                               l = c.GetChildAtPoint (new Point (57, 57), GetChildAtPointSkip.Transparent);
+                               Assert.AreSame (e.Name, l.Name, "Child10");
+
+#endif // NET_2_0
                        } finally {
                                if (c != null)
                                        c.Dispose ();
@@ -1380,6 +2077,24 @@ namespace MonoTests.System.Windows.Forms
                        }
                }
 
+               private class TransparentControl : Control
+               {
+                       public TransparentControl ()
+                       {
+                               SetStyle (ControlStyles.SupportsTransparentBackColor, true);
+                       }
+
+                       protected override CreateParams CreateParams
+                       {
+                               get
+                               {
+                                       CreateParams cp = base.CreateParams;
+                                       cp.ExStyle |= 0x00000020;
+                                       return cp;
+                               }
+                       }
+               }
+               
                [Test]
                public void ResetFontTest ()
                {
@@ -1605,6 +2320,22 @@ namespace MonoTests.System.Windows.Forms
                        f.Dispose ();
                }
 
+               [Test] // bug #330501
+               public void OnValidating_Parent_Close ()
+               {
+                       MockControl control = new MockControl ();
+
+                       Form f = new Form ();
+                       f.Controls.Add (control);
+                       f.ShowInTaskbar = false;
+
+                       f.Show ();
+                       Assert.AreEqual (0, control.OnValidatingCount, "#A1");
+                       f.Close ();
+                       Assert.AreEqual (1, control.OnValidatingCount, "#A2");
+                       f.Dispose ();
+               }
+
                [Test] // bug #80280
                public void Validated_Multiple_Containers ()
                {
@@ -1636,18 +2367,591 @@ namespace MonoTests.System.Windows.Forms
                {
                        ((Control) sender).Tag = false;
                }
+               
+               [Test]
+               public void ControlReparentLocationTest ()
+               {
+                       Form form = new Form ();
+                       Label l = new Label ();
+                       l.Location = new Point (0, 0);
+                       form.Controls.Add (l);
+                       form.Show ();
+                       Assert.AreEqual (0, l.Left, "#A1");
+                       Assert.AreEqual (0, l.Top, "#A2");
+                       form.Hide ();
+                       form.Controls.Remove (l);
+                       form.Show ();
+                       form.Controls.Add (l);
+                       Assert.AreEqual (0, l.Left, "#A3");
+                       Assert.AreEqual (0, l.Top, "#A4");
+                       
+                       form.Dispose ();
+               }
+
+#if NET_2_0
+               [Test]
+               public void UseWaitCursorTest ()
+               {
+                       Control c = new Control ();
+                       Assert.IsFalse (c.UseWaitCursor, "#1");
+                       c.Cursor = Cursors.Hand;
+                       c.UseWaitCursor = true;
+                       Assert.AreEqual (Cursors.WaitCursor, c.Cursor, "#2");
+                       c.UseWaitCursor = false;
+                       Assert.AreEqual (Cursors.Hand, c.Cursor, "#3");
+                       
+                       c.UseWaitCursor = true;
+                       c.Cursor = Cursors.Help;
+                       Assert.AreEqual (Cursors.WaitCursor, c.Cursor, "#4");
+                       Assert.AreEqual (true, c.UseWaitCursor, "#5");
+                       
+                       c.UseWaitCursor = false;
+                       Assert.AreEqual (Cursors.Help, c.Cursor, "#6");
+               }
+
+               [Test] // bug #80621, #81125
+               public void DontCallSizeFromClientSize ()
+               {
+                       SizeControl sc = new SizeControl ();
+                       
+                       Assert.AreEqual (0, sc.size_from_client_size_count, "A1");
+                       
+                       sc.ClientSize = new Size (300, 300);
+                       Assert.AreEqual (0, sc.size_from_client_size_count, "A2");
+                       
+                       SizeForm sf = new SizeForm ();
+                       sf.ShowInTaskbar = false;
+                       sf.Show ();
+                       
+                       Assert.AreEqual (0, sc.size_from_client_size_count, "A3");
+
+                       sc.ClientSize = new Size (300, 300);
+                       Assert.AreEqual (0, sc.size_from_client_size_count, "A4");      
+                       
+                       sf.Dispose ();  
+               }
+               
+               private class SizeControl : Control
+               {
+                       public int size_from_client_size_count = 0;
+                       
+                       protected override Size SizeFromClientSize (Size clientSize)
+                       {
+                               size_from_client_size_count++;
+                               return base.SizeFromClientSize (clientSize);
+                       }
+               }
+
+               private class SizeForm : Form
+               {
+                       public int size_from_client_size_count = 0;
+
+                       protected override Size SizeFromClientSize (Size clientSize)
+                       {
+                               size_from_client_size_count++;
+                               return base.SizeFromClientSize (clientSize);
+                       }
+               }
+#endif
 
                public class MockControl : Control
                {
-                       public int font_height {
+                       public int OnValidatingCount;
+                       public int OnSizeChangedCount;
+                       public int OnResizeCount;
+                       public int OnLocationChangedCount;
+
+                       public MockControl ()
+                       {
+                       }
+
+                       public MockControl (string text)
+                               : base (text)
+                       {
+                       }
+
+                       public MockControl (Control parent, string text)
+                               : base (parent, text)
+                       {
+                       }
+
+                       public MockControl (string text, int left, int top, int width, int height)
+                               : base (text, left, top, width, height)
+                       {
+                       }
+
+                       public MockControl (Control parent, string text, int left, int top, int width, int height)
+                               : base (parent, text, left, top, width, height)
+                       {
+                       }
+
+                       public int font_height
+                       {
                                get { return base.FontHeight; }
                                set { base.FontHeight = value; }
                        }
+
+                       protected override void OnLocationChanged (EventArgs e)
+                       {
+                               OnLocationChangedCount++;
+                               base.OnLocationChanged (e);
+                       }
+
+                       protected override void OnSizeChanged (EventArgs e)
+                       {
+                               OnSizeChangedCount++;
+                               base.OnSizeChanged (e);
+                       }
+
+                       protected override void OnResize (EventArgs e)
+                       {
+                               OnResizeCount++;
+                               base.OnResize (e);
+                       }
+
+                       protected override void OnValidating (CancelEventArgs e)
+                       {
+                               OnValidatingCount++;
+                       }
+               }
+
+               const int WM_KEYDOWN = 0x0100;
+               const int WM_CHAR = 0x0102;
+               const int WM_SYSCHAR = 0x0106;
+               const int WM_KEYUP = 0x0101;
+
+#if NET_2_0
+               [Test]
+               public void MethodPreProcessControlMessage ()
+               {
+                       bool testing_callstack = false;
+
+                       MyControl c = new MyControl ();
+                       Message m = new Message ();
+                       m.HWnd = c.Handle;
+                       m.Msg = WM_KEYDOWN;
+                       m.WParam = (IntPtr)Keys.Down;
+                       m.LParam = IntPtr.Zero;
+
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A1");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.OnPreviewKeyDown);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A2");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.ProcessCmdKey);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A3");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.IsInputKey);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A4");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.ProcessDialogKey);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A5");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+
+                       m.Msg = WM_CHAR;
+                       c.SetState (State.None);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A6");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.IsInputChar);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A7");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.ProcessDialogChar);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A8");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+
+                       m.Msg = WM_SYSCHAR;
+                       c.SetState (State.None);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A9");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.IsInputChar);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (PreProcessControlState.MessageNeeded, c.PreProcessControlMessage (ref m), "A10");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.ProcessDialogChar);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (PreProcessControlState.MessageProcessed, c.PreProcessControlMessage (ref m), "A11");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+
+                       m.Msg = WM_KEYUP;
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A12");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.OnPreviewKeyDown);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A13");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.ProcessCmdKey);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A14");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.IsInputKey);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A15");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.ProcessDialogKey);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (PreProcessControlState.MessageNotNeeded, c.PreProcessControlMessage (ref m), "A16");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+               }
+#endif
+
+               [Test]
+               public void MethodPreProcessMessage ()
+               {
+                       bool testing_callstack = false;
+
+                       MyControl c = new MyControl ();
+                       Message m = new Message ();
+                       m.HWnd = c.Handle;
+                       m.Msg = WM_KEYDOWN;
+                       m.WParam = (IntPtr)Keys.Down;
+                       m.LParam = IntPtr.Zero;
+
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (false, c.PreProcessMessage (ref m), "A1");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.OnPreviewKeyDown);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (false, c.PreProcessMessage (ref m), "A2");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.ProcessCmdKey);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (true, c.PreProcessMessage (ref m), "A3");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.IsInputKey);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (false, c.PreProcessMessage (ref m), "A4");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.ProcessDialogKey);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (true, c.PreProcessMessage (ref m), "A5");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+
+                       m.Msg = WM_CHAR;
+                       c.SetState (State.None);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (false, c.PreProcessMessage (ref m), "A6");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.IsInputChar);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (false, c.PreProcessMessage (ref m), "A7");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.ProcessDialogChar);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (true, c.PreProcessMessage (ref m), "A8");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+
+                       m.Msg = WM_SYSCHAR;
+                       c.SetState (State.None);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (false, c.PreProcessMessage (ref m), "A9");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.IsInputChar);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (false, c.PreProcessMessage (ref m), "A10");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.ProcessDialogChar);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (true, c.PreProcessMessage (ref m), "A11");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+
+                       m.Msg = WM_KEYUP;
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (false, c.PreProcessMessage (ref m), "A12");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.OnPreviewKeyDown);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (false, c.PreProcessMessage (ref m), "A13");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.ProcessCmdKey);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (false, c.PreProcessMessage (ref m), "A14");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.IsInputKey);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (false, c.PreProcessMessage (ref m), "A15");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+
+                       c.SetState (State.ProcessDialogKey);
+                       if (testing_callstack) Console.WriteLine ("Start");
+                       Assert.AreEqual (false, c.PreProcessMessage (ref m), "A16");
+                       if (testing_callstack) Console.WriteLine ("End {0}\n", m.WParam.ToString ());
+               }
+               private enum State
+               {
+                       None,
+                       ProcessCmdKey,
+                       OnPreviewKeyDown,
+                       IsInputChar,
+                       IsInputKey,
+                       PreProcessMessage,
+                       ProcessDialogKey,
+                       ProcessDialogChar
+               }
+
+               private class MyControl : Control
+               {
+
+                       private State current_state;
+                       bool testing_callstack = false;
+
+                       public void SetState (State state)
+                       {
+                               current_state = state;
+                       }
+
+                       protected override bool ProcessCmdKey (ref Message msg, Keys keyData)
+                       {
+                               if (testing_callstack) Console.Write ("ProcessCmdKey[");
+                               if (current_state == State.ProcessCmdKey) {
+                                       if (testing_callstack) Console.WriteLine ("]");
+                                       return true;
+                               }
+
+                               bool retval = base.ProcessCmdKey (ref msg, keyData);
+                               if (testing_callstack) Console.WriteLine ("]");
+                               return retval;
+                       }
+
+#if NET_2_0
+                       protected override void OnPreviewKeyDown (PreviewKeyDownEventArgs e)
+                       {
+                               if (testing_callstack) Console.Write ("OnPreviewKeyDown[");
+                               if (current_state == State.OnPreviewKeyDown) {
+                                       e.IsInputKey = true;
+                                       if (testing_callstack) Console.WriteLine ("]");
+                                       return;
+                               }
+
+                               base.OnPreviewKeyDown (e);
+                               if (testing_callstack) Console.WriteLine ("]");
+                       }
+#endif
+
+                       protected override bool IsInputChar (char charCode)
+                       {
+                               if (testing_callstack) Console.Write ("IsInputChar[");
+                               if (current_state == State.IsInputChar) {
+                                       if (testing_callstack) Console.WriteLine ("true]");
+                                       return true;
+                               }
+
+                               bool retval = base.IsInputChar (charCode);
+                               if (testing_callstack) Console.WriteLine ("{0}]", retval.ToString ());
+                               return retval;
+                       }
+
+                       protected override bool IsInputKey (Keys keyData)
+                       {
+                               if (testing_callstack) Console.Write ("IsInputKey[");
+                               if (current_state == State.IsInputKey) {
+                                       if (testing_callstack) Console.WriteLine ("]");
+                                       return true;
+                               }
+
+                               bool retval = base.IsInputKey (keyData);
+                               if (testing_callstack) Console.WriteLine ("]");
+                               return retval;
+                       }
+
+                       public override bool PreProcessMessage (ref Message msg)
+                       {
+                               if (testing_callstack) Console.Write ("PreProcessMessage[");
+                               if (current_state == State.PreProcessMessage) {
+                                       if (testing_callstack) Console.WriteLine ("]");
+                                       return true;
+                               }
+
+                               bool retval = base.PreProcessMessage (ref msg);
+                               if (testing_callstack) Console.WriteLine ("]");
+                               return retval;
+                       }
+
+                       protected override bool ProcessDialogKey (Keys keyData)
+                       {
+                               if (testing_callstack) Console.Write ("ProcessDialogKey[");
+                               if (current_state == State.ProcessDialogKey) {
+                                       if (testing_callstack) Console.WriteLine ("]");
+                                       return true;
+                               }
+
+                               bool retval = base.ProcessDialogKey (keyData);
+                               if (testing_callstack) Console.WriteLine ("]");
+                               return retval;
+                       }
+
+                       protected override bool ProcessDialogChar (char charCode)
+                       {
+                               if (testing_callstack) Console.Write ("ProcessDialogChar[");
+                               if (current_state == State.ProcessDialogChar) {
+                                       if (testing_callstack) Console.WriteLine ("]");
+                                       return true;
+                               }
+
+                               bool retval = base.ProcessDialogChar (charCode);
+                               if (testing_callstack) Console.WriteLine ("]");
+                               return retval;
+                       }
+               }
+               
+               [Test]
+               public void MethodIsInputChar ()
+               {
+                       // Basically, show that this method always returns false
+                       InputCharControl m = new InputCharControl ();
+                       bool result = false;
+                       
+                       for (int i = 0; i < 256; i++)
+                               result |= m.PublicIsInputChar ((char)i);
+                       
+                       Assert.AreEqual (false, result, "I1");
+               }
+
+               private class InputCharControl : Control
+               {
+                       public bool PublicIsInputChar (char charCode)
+                       {
+                               return base.IsInputChar (charCode);
+                       }
+
+               }
+
+               [Test] // bug #81118, 81718
+               public void VisibleTriggersLayout ()
+               {
+                       Form f = new Form ();
+                       f.ShowInTaskbar = false;
+                       
+                       Control c = new Control ();
+                       c.Visible = false;
+                       
+                       f.Controls.Add (c);
+                       
+                       c.Dock = DockStyle.Fill;
+                       c.Visible = true;
+                       
+                       Assert.AreEqual (f.ClientSize.Width, c.Width, "L1");
+                       
+                       f.Dispose ();
+               }
+               
+               [Test]
+               public void ResumeLayoutEffects ()
+               {
+                       Form f = new Form ();
+                       f.ShowInTaskbar = false;
+                       f.ClientSize = new Size (300, 300);
+                       
+                       Button button1 = new Button ();
+                       f.Controls.Add (button1);
+                       button1.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
+                       button1.Location = new Point (f.ClientSize.Width - button1.Width, f.ClientSize.Height - button1.Height);
+
+                       f.Show ();
+                       
+                       Assert.AreEqual (new Point (225, 277), button1.Location, "A1");
+                       
+                       f.SuspendLayout ();
+                       f.Height += 10;
+                       f.ResumeLayout (false);
+                       f.PerformLayout ();
+
+                       Assert.AreEqual (new Point (225, 277), button1.Location, "A2");
+
+                       f.SuspendLayout ();
+                       f.Height += 10;
+                       f.ResumeLayout ();
+
+                       Assert.AreEqual (new Point (225, 287), button1.Location, "A3");
+                       f.Dispose ();
+               }
+               
+               [Test]
+               public void DisposeEnumerator ()
+               {
+                       // We can modify the collection while looping through it without crashing
+                       Control c = new Control ();
+
+                       c.Controls.Add (new Control ());
+                       c.Controls.Add (new Control ());
+                       
+                       foreach (Control c1 in c.Controls)
+                               c.Controls.Remove (c1);
+               }
+               
+               [Test]
+               public void MethodSetBounds ()
+               {
+                       Control myControl = new Control();
+                       myControl.SetBounds(10, 20, 30, 40);
+                       myControl.SetBounds(50, 60, 70, 70, BoundsSpecified.Location);
+
+                       Assert.AreEqual (new Rectangle (50, 60, 30, 40), myControl.Bounds, "A1");
+               }
+               
+               [Test]
+               public void Bug386450 ()
+               {
+                       // Should not crash.  We have to check for the font object
+                       // being different, not just if they represent the same font.
+                       Form f = new Form ();
+                       Label l = new Label ();
+                       l.Text = "Hello";
+
+                       Font f1 = new Font ("Arial", 12);
+                       Font f2 = new Font ("Arial", 12);
+
+                       l.Font = f1;
+                       l.Font = f2;
+
+                       f1.Dispose ();
+
+                       f.Controls.Add (l);
+                       f.Show ();
+                       f.Dispose ();
                }
        }
 
        [TestFixture]
-       public class ControlSetTopLevelTest
+       public class ControlSetTopLevelTest : TestHelper
        {
                class ControlPoker : Control {
                        public void DoSetTopLevel ()
@@ -1689,19 +2993,21 @@ namespace MonoTests.System.Windows.Forms
                        f.Controls.Add(f1);
                }
                
-               [Category ("NotWorking")]
                [Test]
+               [Category ("NotWorking")]
                public void TestForm ()
                {
                        Form f = new Form ();
                        Assert.IsFalse (f.Visible, "3");
                        f.TopLevel = true;
                        Assert.IsFalse (f.Visible, "4");
+                       
+                       f.Dispose ();
                }
        }
 
        [TestFixture]
-       public class ControlResizeLayoutTest
+       public class ControlResizeLayoutTest : TestHelper
        {
                class ControlPoker : Control {
                        public void DoOnResize ()
@@ -1746,11 +3052,22 @@ namespace MonoTests.System.Windows.Forms
 
                        Assert.AreEqual (0, parent_event, "3");
                }
+               
        }
 
        [TestFixture]
        [Category ("NotWorking")]
-       public class ControlInvokeTest {
+       public class ControlInvokeTest  : TestHelper {
+
+               [TearDown]
+               protected override void TearDown ()
+               {
+                       if (f != null && !f.IsDisposed)                 
+                               f.Dispose ();
+                       base.TearDown ();
+               }
+
+               
                public delegate void TestDelegate ();
 
                Form f;
@@ -1832,7 +3149,7 @@ namespace MonoTests.System.Windows.Forms
        }
 
        [TestFixture]
-       public class ControlWMTest
+       public class ControlWMTest : TestHelper
        {
                [Test]
                public void WM_PARENTNOTIFY_Test ()
@@ -1937,12 +3254,13 @@ namespace MonoTests.System.Windows.Forms
 
 #if NET_2_0
        [TestFixture]
-       public class ControlLayoutTest
+       public class ControlLayoutTest : TestHelper
        {
-               [Test]
-               public void SetUp ()
+               [SetUp]
+               protected override void SetUp ()
                {
                        _layoutCount = 0;
+                       base.SetUp ();
                }
 
                [Test] // bug #80456