Add test for bug 686486.
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / FormTest.cs
index 37f460591f4d569fc94df2c719c8493dcebc6d85..7b446fea570a4bfd9e536c97e57926c483c151b5 100644 (file)
@@ -21,8 +21,593 @@ using CategoryAttribute = NUnit.Framework.CategoryAttribute;
 namespace MonoTests.System.Windows.Forms
 {
        [TestFixture]
-       public class FormTest
+       public class FormTest : TestHelper
        {
+               [Test]
+               public void AcceptButton ()
+               {
+                       Form form = new Form ();
+                       Assert.IsNull (form.AcceptButton, "#A");
+
+                       MockButton buttonA = new MockButton (true);
+                       Assert.IsFalse (buttonA.IsDefaultButton, "#B1");
+                       form.AcceptButton = buttonA;
+                       Assert.IsNotNull (form.AcceptButton, "#B2");
+                       Assert.AreSame (buttonA, form.AcceptButton, "#B3");
+                       Assert.IsTrue (buttonA.IsDefaultButton, "#B4");
+
+                       form.AcceptButton = null;
+                       Assert.IsNull (form.AcceptButton, "#C1");
+                       Assert.IsFalse (buttonA.IsDefaultButton, "#C2");
+
+                       ButtonControl buttonB = new ButtonControl ();
+                       Assert.IsFalse (buttonB.IsDefaultButton, "#D1");
+                       form.AcceptButton = buttonB;
+                       Assert.IsNotNull (form.AcceptButton, "#D2");
+                       Assert.AreSame (buttonB, form.AcceptButton, "#D3");
+                       Assert.IsFalse (buttonA.IsDefaultButton, "#D4");
+                       Assert.IsTrue (buttonB.IsDefaultButton, "#D5");
+
+                       MockButton buttonC = new MockButton (false);
+                       Assert.IsFalse (buttonC.IsDefaultButton, "#E1");
+                       form.AcceptButton = buttonC;
+                       Assert.IsNotNull (form.AcceptButton, "#E2");
+                       Assert.AreSame (buttonC, form.AcceptButton, "#E3");
+                       Assert.IsFalse (buttonC.IsDefaultButton, "#E4");
+                       Assert.IsFalse (buttonA.IsDefaultButton, "#E5");
+                       Assert.IsFalse (buttonB.IsDefaultButton, "#E6");
+               }
+
+               [Test]
+               public void bug_82358 ()
+               {
+                       //Console.WriteLine ("Starting bug_82358");
+                       int sizeable_factor;
+                       int title_bar;
+                       int tool_bar;
+                       int tool_border;
+                       int d3;
+                       int d2;
+
+                       // WinXP, default theme
+                       sizeable_factor = 2;
+                       title_bar = 26;
+                       tool_bar = 18;
+                       tool_border = 6;
+                       d3 = 10;
+                       d2 = 6;
+
+                       // WinXP, Win32 theme:
+                       sizeable_factor = 2;
+                       title_bar = 19;
+                       tool_bar = 16;
+                       tool_border = 6;
+                       d3 = 10;
+                       d2 = 6;
+
+
+                       Size size = new Size (200, 200);
+                       
+                       // Universal theme??
+                       using (Form f = new Form ()) {
+                               f.FormBorderStyle = FormBorderStyle.FixedSingle;
+                               f.Visible = true;
+                               d2 = f.Size.Width - f.ClientSize.Width;
+                               title_bar = f.Size.Height - f.ClientSize.Height - d2;
+                       }
+                       using (Form f = new Form ()) {
+                               f.FormBorderStyle = FormBorderStyle.Sizable;
+                               f.Visible = true;
+                               sizeable_factor = f.Size.Width - f.ClientSize.Width - d2;
+                       }
+                       using (Form f = new Form ()) {
+                               f.ClientSize = size;
+                               f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
+                               //f.Visible = true;
+                               tool_border = f.Size.Width - f.ClientSize.Width;
+                               tool_bar = f.Size.Height - f.ClientSize.Height - tool_border;
+                       }
+                       using (Form f = new Form ()) {
+                               f.FormBorderStyle = FormBorderStyle.Fixed3D;
+                               f.Visible = true;
+                               d3 = f.Size.Width - f.ClientSize.Width; 
+                       }                       
+               
+                       FormBorderStyle style;
+                       
+                       
+                       //Console.WriteLine ("Universal theme says: d2={0}, d3={1}, title_bar={2}, sizeable_factor={3}, tool_border={4}, tool_bar={5}", d2, d3, title_bar, sizeable_factor, tool_border, tool_bar);
+                       
+                       // Changing client size, then FormBorderStyle.
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.FixedToolWindow;
+                               //Console.WriteLine ("Created form, size: {0}, clientsize: {1}", f.Size, f.ClientSize);
+                               f.ClientSize = size;
+                               //Console.WriteLine ("Changed ClientSize, size: {0}, clientsize: {1}", f.Size, f.ClientSize);
+                               f.FormBorderStyle = style;
+                               //Console.WriteLine ("Changed FormBorderStyle, size: {0}, clientsize: {1}", f.Size, f.ClientSize);
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
+                               Assert.AreEqual (new Size (size.Width + tool_border, size.Height + tool_border + tool_bar).ToString (), f.Size.ToString (), style.ToString () + "-A2");
+                               f.Visible = true;
+                               //Console.WriteLine ("Made visible, size: {0}, clientsize: {1}", f.Size, f.ClientSize);
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
+                               Assert.AreEqual (new Size (size.Width + tool_border, size.Height + tool_border + tool_bar).ToString (), f.Size.ToString (), style.ToString () + "-A4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.SizableToolWindow;
+                               f.ClientSize = size;
+                               f.FormBorderStyle = style;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
+                               Assert.AreEqual (new Size (size.Width + tool_border + sizeable_factor, size.Height + tool_border + tool_bar + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-A2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
+                               Assert.AreEqual (new Size (size.Width + tool_border + sizeable_factor, size.Height + tool_border + tool_bar + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-A4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.Fixed3D;
+                               f.ClientSize = size;
+                               f.FormBorderStyle = style;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
+                               Assert.AreEqual (new Size (size.Width + d3, size.Height + title_bar + d3).ToString () , f.Size.ToString (), style.ToString () + "-A2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
+                               Assert.AreEqual (new Size (size.Width + d3, size.Height + title_bar + d3).ToString (), f.Size.ToString (), style.ToString () + "-A4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.FixedDialog;
+                               f.ClientSize = size;
+                               f.FormBorderStyle = style;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
+                               Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-A2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
+                               Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-A4");
+                       
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.FixedSingle;
+                               f.ClientSize = size;
+                               f.FormBorderStyle = style;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
+                               Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-A2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
+                               Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-A4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.None;
+                               f.ClientSize = size;
+                               f.FormBorderStyle = style;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-A2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-A4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.Sizable;
+                               f.ClientSize = size;
+                               f.FormBorderStyle = style;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
+                               Assert.AreEqual (new Size (size.Width + d2 + sizeable_factor, size.Height + title_bar + d2 + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-A2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
+                               Assert.AreEqual (new Size (size.Width + d2 + sizeable_factor, size.Height + title_bar + d2 + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-A4");
+                       }
+                       
+                       
+                       // Changing size, then FormBorderStyle.
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.FixedToolWindow;
+                               f.Size = size;
+                               f.FormBorderStyle = style;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
+                               Assert.AreEqual (new Size (size.Width - tool_border, size.Height - tool_border - tool_bar).ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.SizableToolWindow;
+                               f.Size = size;
+                               f.FormBorderStyle = style;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
+                               Assert.AreEqual (new Size (size.Width - tool_border - sizeable_factor, size.Height - tool_border - tool_bar - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.Fixed3D;
+                               f.Size = size;
+                               f.FormBorderStyle = style;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
+                               Assert.AreEqual (new Size (size.Width - d3, size.Height - title_bar - d3).ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.FixedDialog;
+                               f.Size = size;
+                               f.FormBorderStyle = style;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
+                               Assert.AreEqual (new Size (size.Width - d2, size.Height - title_bar - d2).ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
+
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.FixedSingle;
+                               f.Size = size;
+                               f.FormBorderStyle = style;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
+                               Assert.AreEqual (new Size (size.Width - d2, size.Height - title_bar - d2).ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.None;
+                               f.Size = size;
+                               f.FormBorderStyle = style;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.Sizable;
+                               f.Size = size;
+                               f.FormBorderStyle = style;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
+                       }
+
+
+
+                       // Changing FormBorderStyle, then client size
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.FixedToolWindow;
+                               f.FormBorderStyle = style;
+                               f.ClientSize = size;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
+                               Assert.AreEqual (new Size (size.Width + tool_border, size.Height + tool_border + tool_bar).ToString (), f.Size.ToString (), style.ToString () + "-C2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
+                               Assert.AreEqual (new Size (size.Width + tool_border, size.Height + tool_border + tool_bar).ToString (), f.Size.ToString (), style.ToString () + "-C4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.SizableToolWindow;
+                               f.FormBorderStyle = style;
+                               f.ClientSize = size;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
+                               Assert.AreEqual (new Size (size.Width + tool_border + sizeable_factor, size.Height + tool_border + tool_bar + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-C2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
+                               Assert.AreEqual (new Size (size.Width + tool_border + sizeable_factor, size.Height + tool_border + tool_bar + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-C4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.Fixed3D;
+                               f.FormBorderStyle = style;
+                               f.ClientSize = size;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
+                               Assert.AreEqual (new Size (size.Width + d3, size.Height + title_bar + d3).ToString (), f.Size.ToString (), style.ToString () + "-C2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
+                               Assert.AreEqual (new Size (size.Width + d3, size.Height + title_bar + d3).ToString (), f.Size.ToString (), style.ToString () + "-C4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.FixedDialog;
+                               f.FormBorderStyle = style;
+                               f.ClientSize = size;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
+                               Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-C2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
+                               Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-C4");
+
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.FixedSingle;
+                               f.FormBorderStyle = style;
+                               f.ClientSize = size;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
+                               Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-C2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
+                               Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-C4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.None;
+                               f.FormBorderStyle = style;
+                               f.ClientSize = size;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-C2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-C4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.Sizable;
+                               f.FormBorderStyle = style;
+                               f.ClientSize = size;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
+                               Assert.AreEqual (new Size (size.Width + d2 + sizeable_factor, size.Height + title_bar + d2 + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-C2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
+                               Assert.AreEqual (new Size (size.Width + d2 + sizeable_factor, size.Height + title_bar + d2 + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-C4");
+                       }
+
+
+                       // Changing FormBorderStyle, then size
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.FixedToolWindow;
+                               f.FormBorderStyle = style;
+                               f.Size = size;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D1");
+                               Assert.AreEqual (new Size (size.Width - tool_border, size.Height - tool_border - tool_bar).ToString (), f.ClientSize.ToString (), style.ToString () + "-D2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D3");
+                               Assert.AreEqual (new Size (size.Width - tool_border, size.Height - tool_border - tool_bar).ToString (), f.ClientSize.ToString (), style.ToString () + "-D4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.SizableToolWindow;
+                               f.FormBorderStyle = style;
+                               f.Size = size;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D1");
+                               Assert.AreEqual (new Size (size.Width - tool_border - sizeable_factor, size.Height - tool_border - tool_bar - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-D2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D3");
+                               Assert.AreEqual (new Size (size.Width - tool_border - sizeable_factor, size.Height - tool_border - tool_bar - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-D4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.Fixed3D;
+                               f.FormBorderStyle = style;
+                               f.Size = size;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D1");
+                               Assert.AreEqual (new Size (size.Width - d3, size.Height - title_bar - d3).ToString (), f.ClientSize.ToString (), style.ToString () + "-D2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D3");
+                               Assert.AreEqual (new Size (size.Width - d3, size.Height - title_bar - d3).ToString (), f.ClientSize.ToString (), style.ToString () + "-D4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.FixedDialog;
+                               f.FormBorderStyle = style;
+                               f.Size = size;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D1");
+                               Assert.AreEqual (new Size (size.Width - d2, size.Height - title_bar - d2).ToString (), f.ClientSize.ToString (), style.ToString () + "-D2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D3");
+                               Assert.AreEqual (new Size (size.Width - d2, size.Height - title_bar - d2).ToString (), f.ClientSize.ToString (), style.ToString () + "-D4");
+
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.FixedSingle;
+                               f.FormBorderStyle = style;
+                               f.Size = size;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D1");
+                               Assert.AreEqual (new Size (size.Width - d2, size.Height - title_bar - d2).ToString (), f.ClientSize.ToString (), style.ToString () + "-D2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D3");
+                               Assert.AreEqual (new Size (size.Width - d2, size.Height - title_bar - d2).ToString (), f.ClientSize.ToString (), style.ToString () + "-D4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.None;
+                               f.FormBorderStyle = style;
+                               f.Size = size;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-D1");
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-D3");
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.Sizable;
+                               f.FormBorderStyle = style;
+                               f.Size = size;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D1");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-D2");
+                               f.Visible = true;
+                               Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D3");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-D4");
+                       }
+
+
+
+                       // Set clientsize, then change size, then FormBorderStyle.
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.FixedToolWindow;
+                               f.ClientSize = f.ClientSize;
+                               f.Size = size;
+                               f.FormBorderStyle = style;
+                               // Here we subtract the Sizable borders (default) then add FixedToolWindow's border.
+                               // Note how now the sizes doesn't change when creating the handle.
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + tool_border, size.Height - title_bar - d2 - sizeable_factor + tool_border + tool_bar).ToString (), f.Size.ToString (), style.ToString () + "-E1");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
+                               f.Visible = true;
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + tool_border, size.Height - title_bar - d2 - sizeable_factor + tool_border + tool_bar).ToString (), f.Size.ToString (), style.ToString () + "-E3");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.SizableToolWindow;
+                               f.ClientSize = f.ClientSize;
+                               f.Size = size;
+                               f.FormBorderStyle = style;
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + tool_border + sizeable_factor, size.Height - title_bar - d2 - sizeable_factor + tool_border + tool_bar + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-E1");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
+                               f.Visible = true;
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + tool_border + sizeable_factor, size.Height - title_bar - d2 - sizeable_factor + tool_border + tool_bar + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-E3");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.Fixed3D;
+                               f.ClientSize = f.ClientSize;
+                               f.Size = size;
+                               f.FormBorderStyle = style;
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + d3, size.Height - title_bar - d2 - sizeable_factor + title_bar + d3).ToString (), f.Size.ToString (), style.ToString () + "-E1");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
+                               f.Visible = true;
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + d3, size.Height - title_bar - d2 - sizeable_factor + title_bar + d3).ToString (), f.Size.ToString (), style.ToString () + "-E3");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.FixedDialog;
+                               f.ClientSize = f.ClientSize;
+                               f.Size = size;
+                               f.FormBorderStyle = style;
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + d2, size.Height - title_bar - d2 - sizeable_factor + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-E1");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
+                               f.Visible = true;
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + d2, size.Height - title_bar - d2 - sizeable_factor + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-E3");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
+
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.FixedSingle;
+                               f.ClientSize = f.ClientSize;
+                               f.Size = size;
+                               f.FormBorderStyle = style;
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + d2, size.Height - title_bar - d2 - sizeable_factor + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-E1");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
+                               f.Visible = true;
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + d2, size.Height - title_bar - d2 - sizeable_factor + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-E3");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.None;
+                               f.ClientSize = f.ClientSize;
+                               f.Size = size;
+                               f.FormBorderStyle = style;
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-E1");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
+                               f.Visible = true;
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-E3");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
+                       }
+
+                       using (Form f = new Form ()) {
+                               style = FormBorderStyle.Sizable;
+                               f.ClientSize = f.ClientSize;
+                               f.Size = size;
+                               f.FormBorderStyle = style;
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + d2 + sizeable_factor, size.Height - title_bar - d2 - sizeable_factor + d2 + sizeable_factor + title_bar).ToString (), f.Size.ToString (), style.ToString () + "-E1");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
+                               f.Visible = true;
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor + d2 + sizeable_factor, size.Height - title_bar - d2 - sizeable_factor + d2 + sizeable_factor + title_bar).ToString (), f.Size.ToString (), style.ToString () + "-E3");
+                               Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
+                       }
+
+
+
+
+               }
+
+               [Test] // bug 81969
+               public void StartPositionClosedForm ()
+               {
+                       using (Form form = new Form ()) {
+                               form.StartPosition = FormStartPosition.CenterParent;
+                               form.Load += new EventHandler (CenterDisposedForm_Load);
+                               form.Show ();
+                       }
+
+                       using (Form form = new Form ()) {
+                               form.StartPosition = FormStartPosition.CenterScreen;
+                               form.Load += new EventHandler (CenterDisposedForm_Load);
+                               form.Show ();
+                       }
+
+
+                       using (Form form = new Form ()) {
+                               form.StartPosition = FormStartPosition.Manual;
+                               form.Load += new EventHandler (CenterDisposedForm_Load);
+                               form.Show ();
+                       }
+
+
+                       using (Form form = new Form ()) {
+                               form.StartPosition = FormStartPosition.WindowsDefaultBounds;
+                               form.Load += new EventHandler (CenterDisposedForm_Load);
+                               form.Show ();
+                       }
+
+                       using (Form form = new Form ()) {
+                               form.StartPosition = FormStartPosition.WindowsDefaultLocation;
+                               form.Load += new EventHandler (CenterDisposedForm_Load);
+                               form.Show ();
+                       }
+               }
+               
+               
+               [Test] 
+               [ExpectedException (typeof (ObjectDisposedException))]
+               public void CenterToParentDisposedForm ()
+               {
+                       using (FormHandleTest.ProtectedMethodsForm form = new FormHandleTest.ProtectedMethodsForm ()) {
+                               form.Dispose ();
+                               form.PublicCenterToParent ();
+                       }
+               }
+
+               [Test]
+               [ExpectedException (typeof (ObjectDisposedException))]
+               public void CenterToScreenDisposedForm ()
+               {
+                       using (FormHandleTest.ProtectedMethodsForm form = new FormHandleTest.ProtectedMethodsForm ()) {
+                               form.Dispose ();
+                               form.PublicCenterToScreen ();
+                       }
+               }
+
+               [Test]
+               public void SetStartPositionDisposedForm ()
+               {
+                       using (FormHandleTest.ProtectedMethodsForm form = new FormHandleTest.ProtectedMethodsForm ()) {
+                               form.Dispose ();
+                               form.StartPosition = FormStartPosition.WindowsDefaultLocation;
+                       }
+               }
+
+               private void CenterDisposedForm_Load (object sender, EventArgs e)
+               {
+                       ((Form) sender).Close ();
+               }
+
                [Test]
                public void ShowDialogCloseTest ()
                {
@@ -71,14 +656,14 @@ namespace MonoTests.System.Windows.Forms
                                f.ShowDialog ();
 
                                Assert.AreEqual ("VisibleChanged", f.Reason, "#B0");
-                               Assert.AreEqual (1, log.CountEvents ("Closing"), "#B1");
 #if NET_2_0
+                               Assert.AreEqual (1, log.CountEvents ("Closing"), "#B1");
                                Assert.AreEqual (1, log.CountEvents ("FormClosing"), "#B2");
 #endif
                                Assert.AreEqual (1, log.CountEvents ("HandleDestroyed"), "#B3");
 
-                               Assert.AreEqual (1, log.CountEvents ("Closed"), "#B4");
 #if NET_2_0
+                               Assert.AreEqual (1, log.CountEvents ("Closed"), "#B4");
                                Assert.AreEqual (1, log.CountEvents ("FormClosed"), "#B5");
 #endif
                                Assert.AreEqual (0, log.CountEvents ("Disposed"), "#B6");
@@ -246,8 +831,6 @@ namespace MonoTests.System.Windows.Forms
                                cp = TestHelper.GetCreateParams (frm);
                                Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$A6");
                                Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#A6");
-                               
-
                        }
                }
                
@@ -293,7 +876,6 @@ namespace MonoTests.System.Windows.Forms
                                        frm.Show ();
                                }
 
-
                                using (Form frm = new Form ()) {
                                        frm.MdiParent = Main;
                                        frm.Location = new Point (23, 45);
@@ -330,8 +912,6 @@ namespace MonoTests.System.Windows.Forms
                                        frm.Show ();
                                }
 
-
-
                                using (Form frm = new Form ()) {
                                        frm.MdiParent = Main;
                                        frm.Location = new Point (34, 56);
@@ -449,7 +1029,6 @@ namespace MonoTests.System.Windows.Forms
                                        frm.Show ();
                                }
 
-
                                using (Form frm = new Form ()) {
                                        frm.TopLevel = false;
                                        Main.Controls.Add (frm);
@@ -487,8 +1066,6 @@ namespace MonoTests.System.Windows.Forms
                                        frm.Show ();
                                }
 
-
-
                                using (Form frm = new Form ()) {
                                        frm.TopLevel = false;
                                        Main.Controls.Add (frm);
@@ -526,7 +1103,6 @@ namespace MonoTests.System.Windows.Forms
                                        frm.Show ();
                                }
 
-
                                Main.Size = new Size (600, 600);
                                using (Form frm = new Form ()) {
                                        frm.TopLevel = false;
@@ -567,6 +1143,21 @@ namespace MonoTests.System.Windows.Forms
                        }
                }
                
+               [Test]
+               public void UnparentForm ()
+               {
+                       Form f1 = new Form ();
+                       f1.Show ();
+
+                       Form f2 = new Form ();
+                       f2.TopLevel = false;
+                       f2.Parent = f1;
+                       Assert.AreSame (f1, f2.Parent, "#1");
+                       f2.Show ();
+                       f2.Parent = null;
+                       Assert.IsNull (f2.Parent, "#2");
+               }
+
                [Test] // bug #80791
                public void ClientSizeTest ()
                {
@@ -838,7 +1429,6 @@ namespace MonoTests.System.Windows.Forms
                        myform.Visible = true;
                        myform.Text = "NewForm";
                        myform.Name = "FormTest";
-                       Assert.IsNull (myform.AcceptButton, "#1");
                        Assert.IsNull (myform.ActiveMdiChild, "#2"); 
                        Assert.IsFalse (myform.AutoScale, "#3");
                        Assert.IsNull (myform.CancelButton, "#6");
@@ -1333,6 +1923,21 @@ namespace MonoTests.System.Windows.Forms
                        formE.Dispose ();
                }
 
+               [Test]
+               public void Opacity ()
+               {
+                       Form frm;
+                       using (frm = new Form ()) {
+                               Assert.AreEqual (1.0f, frm.Opacity, "#01-opacity");
+                               frm.Opacity = 0.50;
+                               Assert.AreEqual (0.50f, frm.Opacity, "#02-opacity");
+                               frm.Opacity = -0.1f;
+                               Assert.AreEqual (0, frm.Opacity, "#03-opacity");
+                               frm.Opacity = 1.1f;
+                               Assert.AreEqual (1, frm.Opacity, "#04-opacity");
+                       }
+               }
+
                [Test]
                public void DisposeOwnerTest ()
                {
@@ -1408,19 +2013,22 @@ namespace MonoTests.System.Windows.Forms
                        Assert.IsFalse (myform.IsDisposed, "A2");
 
                        myform.Close ();
-
-                       Assert.IsFalse (myform.Visible, "A3");
-                       Assert.IsFalse (myform.IsDisposed, "A4");
+#if NET_2_0
+                       Assert.IsTrue (myform.IsDisposed, "A3");
+#else
+                       Assert.IsFalse (myform.Visible, "A4");
+                       Assert.IsFalse (myform.IsDisposed, "A5");
 
                        myform.Show ();
 
-                       Assert.IsTrue (myform.Visible, "A5");
-                       Assert.IsFalse (myform.IsDisposed, "A6");
+                       Assert.IsTrue (myform.Visible, "A6");
+                       Assert.IsFalse (myform.IsDisposed, "A7");
 
                        myform.Close ();
 
-                       Assert.IsFalse (myform.Visible, "A7");
-                       Assert.IsTrue (myform.IsDisposed, "A8");
+                       Assert.IsFalse (myform.Visible, "A8");
+                       Assert.IsTrue (myform.IsDisposed, "A9");
+#endif
                }
 
                [Test]
@@ -1433,11 +2041,13 @@ namespace MonoTests.System.Windows.Forms
                        Assert.IsFalse (f.Visible, "A1");
                        f.Close ();
                        Assert.AreEqual (0, f.close_count, "A2");
-
-
+#if NET_2_0
+                       Assert.IsTrue (f.IsDisposed, "A3");
+#else
                        f.Show ();
                        f.Close ();
-                       Assert.AreEqual (1, f.close_count, "A3");
+                       Assert.AreEqual (1, f.close_count, "A4");
+#endif
                }
 
                class WMCloseWatcher : Form {
@@ -1476,9 +2086,9 @@ namespace MonoTests.System.Windows.Forms
                [Test]
                public void OnActivateEventHandlingTest1 ()
                {
-                       if (TestHelper.RunningOnUnix) {
-                               Assert.Ignore ("Relies on form.Show() synchronously generating WM_ACTIVATE");
-                       }
+//                     if (TestHelper.RunningOnUnix) {
+//                             Assert.Ignore ("Relies on form.Show() synchronously generating WM_ACTIVATE");
+//                     }
 
                        SwallowOnActivated f = new SwallowOnActivated ();
 
@@ -1698,6 +2308,39 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4");
                }
 #endif
+
+               [Test]  // bug #438866
+               public void MinMaxSize ()
+               {
+                       Form f = new Form ();
+                       
+                       f.MinimumSize = new Size (200, 200);
+                       f.MaximumSize = new Size (150, 150);
+
+                       Assert.AreEqual (new Size (150, 150), f.MinimumSize, "A1");
+                       Assert.AreEqual (new Size (150, 150), f.MaximumSize, "A2");
+                       
+                       f.MinimumSize = new Size (200, 200);
+
+                       Assert.AreEqual (new Size (200, 200), f.MinimumSize, "A3");
+                       Assert.AreEqual (new Size (200, 200), f.MaximumSize, "A4");
+                       
+                       f.Dispose ();
+               }
+
+               [Test]
+               public void MinSizeIssue ()
+               {
+                       Form f = new Form ();
+
+                       f.MinimumSize = new Size (100, 100);
+
+                       f.Show ();
+
+                       Assert.AreEqual (new Size (300, 300), f.Size, "A1");
+
+                       f.Dispose ();
+               }
                
                [Test]  // Bug #81582
                [Category ("NotWorking")]
@@ -1730,7 +2373,35 @@ namespace MonoTests.System.Windows.Forms
                        }
                }
 
-               [Test]  // Bug #80773
+               [Test] // bug #339641
+               public void ChildFocused ()
+               {
+//                     if (TestHelper.RunningOnUnix) {
+//                             Assert.Ignore ("Relies on form.Show() synchronously generating WM_ACTIVATE");
+//                     }
+                       using (Form f = new TimeBombedForm ()) {
+                               TreeView tv = new TreeView ();
+                               EventLogger log = new EventLogger (tv);
+                               tv.GotFocus += new EventHandler (tv_GotFocus);
+                               f.Activated += new EventHandler (f_Activated);
+                               f.Controls.Add (tv);
+                               f.Show ();
+                               Assert.IsTrue (log.EventRaised ("GotFocus"), "#01");
+                       }
+               }
+
+               void f_Activated (object sender, EventArgs e)
+               {
+                       //Console.WriteLine ("         ACTIVATED");
+                       //Console.WriteLine (Environment.StackTrace);
+               }
+
+               void tv_GotFocus (object sender, EventArgs e)
+               {
+                       //Console.WriteLine (Environment.StackTrace);
+               }
+
+               [Test]  // bug #80773
                public void DontSetOwnerOnShowDialogException ()
                {
                        Form f = new Form ();
@@ -1757,6 +2428,246 @@ namespace MonoTests.System.Windows.Forms
                        f.Dispose ();
                }
 
+               [Test]
+               public void Bug82470 ()
+               {
+                       Form f = new Form ();
+                       f.Load += new EventHandler (Form_LoadAndHide);
+                       f.Show ();
+                       
+                       Assert.AreEqual (true, f.Visible, "A1");
+                       
+                       f.Dispose ();
+               }
+
+               private void Form_LoadAndHide (object sender, EventArgs e)
+               {
+                       ((Form)sender).Visible = false;
+               }
+
+               [Test]
+               public void Bug686486 ()
+               {
+                       using (Form f = new Bug686486Form ())
+                       {
+                               try
+                               {
+                                       f.ShowDialog ();
+                               }
+                               catch (StackOverflowException)
+                               {
+                                       Assert.Fail ("Setting DialogResult in FormClosing Event causes endless loop: StackOverflowException");
+                               }
+                       }
+               }
+
+               private class Bug686486Form : Form
+               {
+                       public Bug686486Form ()
+                       {
+                               this.FormClosing += SetDialogResultOK;
+                               this.Load += SetDialogResultOK;
+                       }
+
+                       private void SetDialogResultOK (object sender, EventArgs e)
+                       {
+                               this.DialogResult = DialogResult.OK;
+                       }
+               }
+
+#if NET_2_0
+               [Test]
+               public void AutoSizeGrowOnly ()
+               {
+                       Form f = new Form ();
+                       f.ShowInTaskbar = false;
+                       f.AutoSize = true;
+
+                       Button b = new Button ();
+                       b.Size = new Size (200, 200);
+                       b.Location = new Point (200, 200);
+                       f.Controls.Add (b);
+
+                       f.Show ();
+
+                       Assert.AreEqual (new Size (403, 403), f.ClientSize, "A1");
+                       
+                       f.Controls.Remove (b);
+                       Assert.AreEqual (new Size (403, 403), f.ClientSize, "A2");
+               
+                       f.Dispose ();
+               }
+
+               [Test]
+               public void AutoSizeReset ()
+               {
+                       Form f = new Form ();
+                       f.ShowInTaskbar = false;
+
+                       Button b = new Button ();
+                       b.Size = new Size (200, 200);
+                       b.Location = new Point (200, 200);
+                       f.Controls.Add (b);
+
+                       f.Show ();
+
+                       Size start_size = f.ClientSize;
+
+                       f.AutoSize = true;
+                       Assert.AreEqual (new Size (403, 403), f.ClientSize, "A1");
+
+                       f.AutoSize = false;
+                       Assert.AreEqual (start_size, f.ClientSize, "A2");
+                       f.Close ();
+               }
+
+               [Test]
+               public void AutoSizeGrowAndShrink ()
+               {
+                       Form f = new Form ();
+                       f.ShowInTaskbar = false;
+                       f.AutoSize = true;
+                       f.AutoSizeMode = AutoSizeMode.GrowAndShrink;
+
+                       f.Show ();
+
+                       // Make sure form shrunk
+                       Assert.IsTrue (f.ClientSize.Width < 150, "A1");
+                       Assert.IsTrue (f.ClientSize.Height < 150, "A1-2");
+
+                       Button b = new Button ();
+                       b.Size = new Size (200, 200);
+                       b.Location = new Point (0, 0);
+                       f.Controls.Add (b);
+
+                       Assert.AreEqual (new Size (203, 203), f.ClientSize, "A2");
+                       f.Dispose ();
+               }
+
+               [Test]
+               public void GetScaledBoundsTest ()
+               {
+                       if (TestHelper.RunningOnUnix)
+                               Assert.Ignore ("Depends on WM decoration sizes, values correspond to windows");
+
+                       ScaleForm c = new ScaleForm ();
+
+                       Rectangle r = new Rectangle (100, 200, 300, 400);
+
+                       Assert.AreEqual (new Rectangle (100, 200, 584, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A1");
+                       Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A2");
+                       Assert.AreEqual (new Rectangle (100, 200, 584, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A3");
+                       Assert.AreEqual (new Rectangle (100, 200, 300, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A4");
+                       Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A5");
+                       Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A6");
+
+                       Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (1f, 1f), BoundsSpecified.All), "A6-2");
+                       Assert.AreEqual (new Rectangle (100, 200, 584, 764), c.PublicGetScaledBounds (r, new SizeF (2f, 2f), BoundsSpecified.All), "A7");
+                       Assert.AreEqual (new Rectangle (100, 200, 868, 1128), c.PublicGetScaledBounds (r, new SizeF (3f, 3f), BoundsSpecified.All), "A8");
+                       Assert.AreEqual (new Rectangle (100, 200, 1152, 1492), c.PublicGetScaledBounds (r, new SizeF (4f, 4f), BoundsSpecified.All), "A9");
+                       Assert.AreEqual (new Rectangle (100, 200, 158, 218), c.PublicGetScaledBounds (r, new SizeF (.5f, .5f), BoundsSpecified.All), "A10");
+               }
+
+               [Test]
+               public void MethodScaleControl ()
+               {
+                       if (TestHelper.RunningOnUnix)
+                               Assert.Ignore ("Depends on WM decoration sizes, values correspond to windows");
+                       
+                       ScaleForm f = new ScaleForm ();
+                       f.Location = new Point (5, 10);
+
+                       Assert.AreEqual (new Rectangle (5, 10, 300, 300), f.Bounds, "A1");
+
+                       f.PublicScaleControl (new SizeF (2.0f, 2.0f), BoundsSpecified.All);
+                       Assert.AreEqual (new Rectangle (5, 10, 584, 564), f.Bounds, "A2");
+
+                       f.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Location);
+                       Assert.AreEqual (new Rectangle (5, 10, 584, 564), f.Bounds, "A3");
+
+                       f.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Size);
+                       Assert.AreEqual (new Rectangle (5, 10, 300, 300), f.Bounds, "A4");
+
+                       f.PublicScaleControl (new SizeF (2.5f, 2.5f), BoundsSpecified.Size);
+                       Assert.AreEqual (new Rectangle (5, 10, 726, 696), f.Bounds, "A5");
+
+                       f.PublicScaleControl (new SizeF (.3f, .3f), BoundsSpecified.Size);
+                       Assert.AreEqual (new Rectangle (5, 10, 229, 234), f.Bounds, "A6");
+
+                       f.Dispose ();
+               }
+
+               private class ScaleForm : Form
+               {
+                       public Rectangle PublicGetScaledBounds (Rectangle bounds, SizeF factor, BoundsSpecified specified)
+                       {
+                               return base.GetScaledBounds (bounds, factor, specified);
+                       }
+
+                       public void PublicScaleControl (SizeF factor, BoundsSpecified specified)
+                       {
+                               base.ScaleControl (factor, specified);
+                       }
+               }
+#endif
+               [Test]
+               public void Bug325436 ()
+               {
+                       Form f = new Form ();
+                       f.ShowInTaskbar = false;
+                       f.ClientSize = new Size (320, 40);
+                       f.ControlBox = false;
+                       f.FormBorderStyle = FormBorderStyle.None;
+                       f.MaximizeBox = false;
+                       f.MinimizeBox = false;
+                       
+                       f.Show ();
+                       Assert.AreEqual (new Size (320, 40), f.ClientSize, "A1");
+                       f.Dispose ();
+
+                       f = new Form ();
+                       f.ShowInTaskbar = false;
+                       f.ControlBox = false;
+                       f.FormBorderStyle = FormBorderStyle.None;
+                       f.MaximizeBox = false;
+                       f.MinimizeBox = false;
+                       f.ClientSize = new Size(320, 40);
+                       
+                       f.Show ();
+                       Assert.AreEqual (new Size (320, 40), f.ClientSize, "A2");
+                       f.Dispose ();
+               }
+
+#if NET_2_0
+               #region PreferredSize
+               [Test]
+               public void PreferredSize ()
+               {
+                       PreferredSizeForm form = new PreferredSizeForm ();
+                       form.AutoSize = true;
+                       Control control = new Control ();
+                       form.Controls.Add (control);
+                       control.Size = new Size (500, 500);
+                       form.Test ();
+                       form.Controls.Clear ();
+                       form.Test2 ();
+
+               }
+
+               private class PreferredSizeForm : Form
+               {
+                       public void Test ()
+                       {
+                               Assert.AreEqual (SizeFromClientSize (new Size (503, 503)), PreferredSize, "1");
+                       }
+
+                       public void Test2 ()
+                       {
+                               Assert.AreEqual (SizeFromClientSize (new Size (0, 0)), PreferredSize, "1");
+                       }
+               }
+               #endregion
+#endif
                private class MockForm : Form
                {
                        public bool CloseOnLoad {
@@ -1777,7 +2688,288 @@ namespace MonoTests.System.Windows.Forms
 
                        private bool _closeOnLoad;
                        private bool _visibleOnLoad;
-               }       
+               }
+
+               private class MockButton : Button
+               {
+                       public MockButton (bool notify)
+                       {
+                               _notify = notify;
+                       }
+
+                       public bool Notify {
+                               get { return _notify; }
+                               set { _notify = value; }
+                       }
+
+                       public bool IsDefaultButton
+                       {
+                               get { return base.IsDefault; }
+                               set { base.IsDefault = value; }
+                       }
+
+                       public override void NotifyDefault (bool value)
+                       {
+                               if (Notify)
+                                       base.NotifyDefault (value);
+                       }
+
+                       private bool _notify;
+               }
+
+               private class ButtonControl : IButtonControl
+               {
+                       public DialogResult DialogResult {
+                               get { return _dialogResult; }
+                               set { _dialogResult = value; }
+                       }
+
+                       public bool IsDefaultButton {
+                               get { return _isDefault; }
+                       }
+
+                       public void NotifyDefault (bool value)
+                       {
+                               _isDefault = value;
+                       }
+
+                       public void PerformClick ()
+                       {
+                       }
+
+                       private bool _isDefault;
+                       private DialogResult _dialogResult = DialogResult.None;
+               }
+               
+#if NET_2_0
+               [Test]
+               public void RestoreBounds ()
+               {
+                       Form f = new Form ();
+                       f.Show ();
+                       
+                       Assert.AreEqual (new Size (300, 300), f.RestoreBounds.Size, "A1");
+                       
+                       // Move the form
+                       f.Location = new Point (0, 0);
+                       Assert.AreEqual (new Rectangle (0, 0, 300, 300), f.RestoreBounds, "A2");
+                       
+                       // Resize the form
+                       f.Size = new Size (250, 250);
+                       Assert.AreEqual (new Rectangle (0, 0, 250, 250), f.RestoreBounds, "A3");
+                       
+                       // Minimize the form
+                       f.WindowState = FormWindowState.Minimized;
+                       Assert.AreEqual (new Rectangle (0, 0, 250, 250), f.RestoreBounds, "A4");
+
+                       // Move the form (while minimized)
+                       f.Location = new Point (10, 10);
+                       Assert.AreEqual (new Rectangle (10, 10, 250, 250), f.RestoreBounds, "A5");
+
+                       // Resize the form (while minimized)
+                       f.Size = new Size (275, 275);
+                       Assert.AreEqual (new Rectangle (10, 10, 275, 275), f.RestoreBounds, "A6");
+                       
+                       // Maximize the form
+                       f.WindowState = FormWindowState.Maximized;
+                       Assert.AreEqual (new Rectangle (10, 10, 275, 275), f.RestoreBounds, "A7");
+
+                       // Move the form (while maximized)
+                       f.Location = new Point (20, 20);
+                       Assert.AreEqual (new Rectangle (20, 20, 275, 275), f.RestoreBounds, "A8");
+
+                       // Resize the form (while maximized)
+                       f.Size = new Size (285, 285);
+                       Assert.AreEqual (new Rectangle (20, 20, 285, 285), f.RestoreBounds, "A9");
+                       
+                       f.Dispose ();
+               }
+               
+               [Test]  // Bug 353827
+               public void AutoScaleModeTest ()
+               {
+                       Form f = new Form ();
+                       
+                       // AutoScale starts off true
+                       Assert.AreEqual (true, f.AutoScale, "A1");
+                       
+                       // Setting AutoScaleMode turns AutoScale off
+                       f.AutoScaleMode = AutoScaleMode.Font;
+                       Assert.AreEqual (false, f.AutoScale, "A2");
+                       Assert.AreEqual (AutoScaleMode.Font, f.AutoScaleMode, "A3");
+
+                       // Changing Font resets AutoScaleBaseSize..
+                       f.Font = new Font ("Arial", 10);
+                       Assert.AreEqual (RoundSizeF (Form.GetAutoScaleSize (f.Font)), f.AutoScaleBaseSize, "A4");
+
+                       f.Font = new Font ("Arial", 12);
+                       Assert.AreEqual (RoundSizeF (Form.GetAutoScaleSize (f.Font)), f.AutoScaleBaseSize, "A5");
+                       
+                       // ..Until AutoScaleBaseSize is explicitly set
+                       f.AutoScaleBaseSize = new Size (5, 13);
+                       Assert.AreEqual (new Size (5, 13), f.AutoScaleBaseSize, "A6");
+
+                       f.Font = new Font ("Arial", 14F);
+                       Assert.IsTrue (RoundSizeF (Form.GetAutoScaleSize (f.Font)) != f.AutoScaleBaseSize, "A5");
+       
+                       f.Dispose ();
+               }
+               
+               private Size RoundSizeF (SizeF sizef)
+               {
+                       return new Size ((int)Math.Round (sizef.Width), (int)Math.Round (sizef.Height));
+               }
+               
+               [Test] // Bug 354669
+               public void AutoScaleDetails ()
+               {
+                       ProtectedForm f = new ProtectedForm ();
+                       f.Show ();
+                       
+                       f.SuspendLayout ();
+                       
+                       // First AutoScaleMode shouldn't reset AutoScaleDimensions
+                       f.AutoScaleDimensions = new SizeF (3F, 3F);
+                       f.AutoScaleMode = AutoScaleMode.Font;
+                       Assert.AreEqual (new SizeF (3F, 3F), f.AutoScaleDimensions, "A1");
+                       
+                       // Subsequent calls will reset it to 0, 0
+                       f.AutoScaleMode = AutoScaleMode.Dpi;
+                       Assert.AreEqual (SizeF.Empty, f.AutoScaleDimensions, "A2");
+
+                       f.ResumeLayout ();
+                       
+                       // CurrentAutoScaleDimensions should be nonzero
+                       Assert.IsFalse (f.CurrentAutoScaleDimensions == SizeF.Empty, "A3");
+                       
+                       // AutoScaleDimensions and CurrentAutoScaleDimensions should match after ResumeLayout
+                       Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A4");
+
+                       // CurrentAutoScaleDimensions should match AutoScaleDimensions for AutoScaleMode.None
+                       f.SuspendLayout ();
+                       f.AutoScaleMode = AutoScaleMode.None;
+                       f.AutoScaleDimensions = new SizeF (5F, 5F);
+
+                       Assert.AreEqual (new SizeF (5F, 5F), f.AutoScaleDimensions, "A5");
+                       Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A6");
+
+                       // ResumeLayout changes nothing
+                       f.ResumeLayout ();
+
+                       Assert.AreEqual (new SizeF (5F, 5F), f.AutoScaleDimensions, "A7");
+                       Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A8");
+
+                       // AutoScaleFactor should be ~2,2 if PerformAutoScale hasn't run
+                       f.ClientSize = new Size (150, 150);
+                       f.SuspendLayout ();
+                       f.AutoScaleMode = AutoScaleMode.Dpi;
+                       f.AutoScaleDimensions = new SizeF (f.CurrentAutoScaleDimensions.Width / 2F, f.CurrentAutoScaleDimensions.Height / 2F);
+                       f.ClientSize = new Size (200, 200);
+
+                       Assert.AreEqual (new Size (2, 2), RoundSizeF (f.GetPublicAutoScaleFactor ()), "A9");
+
+                       // AutoScaleFactor should be 1 after ResumeLayout
+                       f.ResumeLayout ();
+
+                       Assert.AreEqual (new SizeF (1F, 1F), f.GetPublicAutoScaleFactor (), "A10");
+                       Assert.AreEqual (new Size (400, 400), f.ClientSize, "A11");
+                       
+                       // PerformAutoScale happens immediately when layout not suspended
+                       f.ClientSize = new Size (125, 125);
+                       f.AutoScaleDimensions = new SizeF (f.CurrentAutoScaleDimensions.Width / 2F, f.CurrentAutoScaleDimensions.Height / 2F);
+                       Assert.AreEqual (new Size (250, 250), f.ClientSize, "A12");
+                       
+                       f.Dispose ();
+               }
+               
+               private class ProtectedForm : Form
+               {
+                       public SizeF GetPublicAutoScaleFactor ()
+                       {
+                               return AutoScaleFactor;
+                       }
+               }
+               
+               [Test] // Bug #355703
+               public void AutoScaleSticks ()
+               {
+                       Form f = new Form ();
+
+                       f.AutoScale = false;
+                       Assert.AreEqual (false, f.AutoScale, "A1");
+
+                       f.AutoScale = true;
+                       Assert.AreEqual (true, f.AutoScale, "A2");
+                       
+                       f.AutoScaleMode = AutoScaleMode.None;
+                       Assert.AreEqual (false, f.AutoScale, "A3");
+               }
+#endif
+
+               [Test] // Bug #359098
+               public void AutoScaleBounds ()
+               {
+                       AutoScaleForm a = new AutoScaleForm (false);
+                       a.Show ();
+                       Assert.AreEqual (new Size (213, 121), a.ClientSize, "A0");
+                       Assert.AreEqual (new Rectangle (  5, 107, 132,  9), new Rectangle (a.hScrollBar1.Location, a.hScrollBar1.Size), "A1");
+                       Assert.AreEqual (new Rectangle (151,  74,  60, 44), new Rectangle (a.treeView1.Location, a.treeView1.Size), "A2");
+                       Assert.AreEqual (new Rectangle (197,  21,   9, 39), new Rectangle (a.vScrollBar1.Location, a.vScrollBar1.Size), "A3");
+                       Assert.AreEqual (new Rectangle (139,  21,  54, 49), new Rectangle (a.listView1.Location, a.listView1.Size), "A4");
+                       Assert.AreEqual (new Rectangle ( 70,   5,  65, 37), new Rectangle (a.textBox2.Location, a.textBox2.Size), "A5");
+                       Assert.AreEqual (new Rectangle (139,   5,  70,  0), new Rectangle (a.comboBox1.Location, new Size (a.comboBox1.Width, 0)), "A6");
+                       Assert.AreEqual (new Rectangle (  5,  77,  43, 13), new Rectangle (a.button2.Location, a.button2.Size), "A7");
+                       Assert.AreEqual (new Rectangle ( 70,  44,  65, 37), new Rectangle (a.richTextBox1.Location, a.richTextBox1.Size), "A8");
+                       Assert.AreEqual (new Rectangle ( 53,  86,  21,  7), new Rectangle (a.label1.Location,a.label1.Size), "A9");
+                       Assert.AreEqual (new Rectangle ( 65,  84,  58,  0), new Rectangle (a.textBox1.Location, new Size (a.textBox1.Width, 0)), "A10");
+                       Assert.AreEqual (new Rectangle (  5,  63,  43, 13), new Rectangle (a.button1.Location, a.button1.Size), "A11");
+                       Assert.AreEqual (new Rectangle (  5,   5,  60, 47), new Rectangle (a.listBox1.Location, a.listBox1.Size), "A12");
+                       a.Dispose ();
+
+#if NET_2_0
+                       a = new AutoScaleForm (true);
+                       a.Show ();
+                       Assert.AreEqual (new Size (184, 104), a.ClientSize, "B0");
+                       Assert.AreEqual (new Rectangle (  4, 92, 114, 16), new Rectangle (a.hScrollBar1.Location, a.hScrollBar1.ClientSize), "B1");
+                       Assert.AreEqual (new Rectangle (130, 64,  50, 36), new Rectangle (a.treeView1.Location, a.treeView1.ClientSize), "B2");
+                       Assert.AreEqual (new Rectangle (170, 18,  16, 34), new Rectangle (a.vScrollBar1.Location, a.vScrollBar1.ClientSize), "B3");
+                       Assert.AreEqual (new Rectangle (120, 18,  44, 40), new Rectangle (a.listView1.Location, a.listView1.ClientSize), "B4");
+                       Assert.AreEqual (new Rectangle ( 60,  4,  54, 30), new Rectangle (a.textBox2.Location, a.textBox2.ClientSize), "B5");
+                       Assert.AreEqual (new Rectangle (120,  4,  62,  0), new Rectangle (a.comboBox1.Location, new Size (a.comboBox1.ClientSize.Width, 0)), "B6");
+                       Assert.AreEqual (new Rectangle (  4, 66,  38, 12), new Rectangle (a.button2.Location, a.button2.ClientSize), "B7");
+                       Assert.AreEqual (new Rectangle ( 60, 38,  54, 30), new Rectangle (a.richTextBox1.Location, a.richTextBox1.ClientSize), "B8");
+                       Assert.AreEqual (new Rectangle ( 46, 74,  18,  6), new Rectangle (a.label1.Location,a.label1.ClientSize), "B9");
+                       Assert.AreEqual (new Rectangle ( 56, 72,  48,  0), new Rectangle (a.textBox1.Location, new Size (a.textBox1.ClientSize.Width, 0)), "B10");
+                       Assert.AreEqual (new Rectangle (  4, 54,  38, 12), new Rectangle (a.button1.Location, a.button1.ClientSize), "B11");
+                       Assert.AreEqual (new Rectangle (  4,  4,  50, 39), new Rectangle (a.listBox1.Location, a.listBox1.ClientSize), "B12");
+                       a.Dispose ();
+#endif
+               }
+
+               [Test]
+               public void SettingIconToNull ()
+               {
+                       Form form = new Form ();
+                       Assert.IsNotNull (form.Icon, "1");
+                       form.Icon = null;
+                       Assert.IsNotNull (form.Icon, "2");
+               }
+
+               [Test]
+               [Category ("NotWorking")]
+               public void MinimizedWindowSize ()
+               {
+                       Form form = new Form ();
+                       form.WindowState = FormWindowState.Minimized;
+                       form.Show ();
+                       Assert.AreEqual (SystemInformation.MinimizedWindowSize, form.Size, "1");
+                       form.Close ();
+                       form = new Form ();
+                       form.Show ();
+                       form.WindowState = FormWindowState.Minimized;
+                       Assert.AreEqual (SystemInformation.MinimizedWindowSize, form.Size, "2");
+                       form.Close ();
+               }
        }
 
        public class TimeBombedForm : Form
@@ -1788,7 +2980,7 @@ namespace MonoTests.System.Windows.Forms
                public TimeBombedForm ()
                {
                        timer = new Timer ();
-                       timer.Interval = 100;
+                       timer.Interval = 500;
                        timer.Tick += new EventHandler (timer_Tick);
                        timer.Start ();
                }
@@ -1808,4 +3000,63 @@ namespace MonoTests.System.Windows.Forms
                        }
                }
        }
+
+       public class AutoScaleForm : Form
+       {
+               public ListBox listBox1 = new ListBox ();
+               public ComboBox comboBox1 = new ComboBox ();
+               public Button button1 = new Button ();
+               public Button button2 = new Button ();
+               public Label label1 = new Label ();
+               public TextBox textBox1 = new TextBox ();
+               public TextBox textBox2 = new TextBox ();
+               public RichTextBox richTextBox1 = new RichTextBox ();
+               public ListView listView1 = new ListView ();
+               public TreeView treeView1 = new TreeView ();
+               public VScrollBar vScrollBar1 = new VScrollBar ();
+               public HScrollBar hScrollBar1 = new HScrollBar ();
+
+               public AutoScaleForm (bool use_new_auto_scale)
+               {
+                       ShowInTaskbar = false;
+                       
+                       SuspendLayout ();
+
+                       listBox1.IntegralHeight = false;
+                       listBox1.SetBounds (8, 8, 104, 82);
+                       comboBox1.SetBounds (240, 8, 121, 21);
+                       button1.SetBounds (8, 108, 75, 23);
+                       button2.SetBounds (8, 132, 75, 23);
+                       label1.SetBounds (92, 148, 35, 13);
+                       textBox1.SetBounds (112, 144, 100, 20);
+                       textBox2.Multiline = true;
+                       textBox2.SetBounds (120, 8, 112, 64);
+                       richTextBox1.SetBounds (120, 76, 112, 64);
+                       listView1.SetBounds (240, 36, 92, 84);
+                       treeView1.SetBounds (260, 128, 104, 76);
+                       vScrollBar1.SetBounds (340, 36, 16, 68);
+                       hScrollBar1.SetBounds (8, 184, 228, 16);
+
+                       ClientSize = new Size (368, 209);
+
+                       Controls.AddRange ( new Control [] { listBox1, comboBox1, button1, button2, label1, textBox1,
+                               textBox2, richTextBox1, listView1, treeView1, vScrollBar1, hScrollBar1 } );
+
+                       if (use_new_auto_scale) {
+#if NET_2_0
+                               AutoScaleMode = AutoScaleMode.Dpi;
+                               SizeF s = CurrentAutoScaleDimensions;
+                               AutoScaleDimensions = new SizeF (s.Width * 2, s.Height * 2);
+#endif
+                       }
+                       else {
+                               AutoScale = true;
+                               SizeF s = Form.GetAutoScaleSize (Font);
+                               AutoScaleBaseSize = new Size ((int)Math.Round (s.Width) * 2, (int)s.Height * 2);
+                       }
+
+                       ResumeLayout (false);
+                       PerformLayout ();
+               }
+       }
 }