importing messaging-2008 branch to trunk.
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / FormTest.cs
1 //
2 // FormTest.cs: Test cases for Form.
3 //
4 // Author:
5 //   Ritvik Mayank (mritvik@novell.com)
6 //
7 // (C) 2005 Novell, Inc. (http://www.novell.com)
8 //
9
10 using System;
11 using System.ComponentModel;
12 using System.Drawing;
13 using System.Reflection;
14 using System.Windows.Forms;
15 using System.Collections;
16
17 using NUnit.Framework;
18
19 using CategoryAttribute = NUnit.Framework.CategoryAttribute;
20
21 namespace MonoTests.System.Windows.Forms
22 {
23         [TestFixture]
24         public class FormTest : TestHelper
25         {
26                 [Test]
27                 public void AcceptButton ()
28                 {
29                         Form form = new Form ();
30                         Assert.IsNull (form.AcceptButton, "#A");
31
32                         MockButton buttonA = new MockButton (true);
33                         Assert.IsFalse (buttonA.IsDefaultButton, "#B1");
34                         form.AcceptButton = buttonA;
35                         Assert.IsNotNull (form.AcceptButton, "#B2");
36                         Assert.AreSame (buttonA, form.AcceptButton, "#B3");
37                         Assert.IsTrue (buttonA.IsDefaultButton, "#B4");
38
39                         form.AcceptButton = null;
40                         Assert.IsNull (form.AcceptButton, "#C1");
41                         Assert.IsFalse (buttonA.IsDefaultButton, "#C2");
42
43                         ButtonControl buttonB = new ButtonControl ();
44                         Assert.IsFalse (buttonB.IsDefaultButton, "#D1");
45                         form.AcceptButton = buttonB;
46                         Assert.IsNotNull (form.AcceptButton, "#D2");
47                         Assert.AreSame (buttonB, form.AcceptButton, "#D3");
48                         Assert.IsFalse (buttonA.IsDefaultButton, "#D4");
49                         Assert.IsTrue (buttonB.IsDefaultButton, "#D5");
50
51                         MockButton buttonC = new MockButton (false);
52                         Assert.IsFalse (buttonC.IsDefaultButton, "#E1");
53                         form.AcceptButton = buttonC;
54                         Assert.IsNotNull (form.AcceptButton, "#E2");
55                         Assert.AreSame (buttonC, form.AcceptButton, "#E3");
56                         Assert.IsFalse (buttonC.IsDefaultButton, "#E4");
57                         Assert.IsFalse (buttonA.IsDefaultButton, "#E5");
58                         Assert.IsFalse (buttonB.IsDefaultButton, "#E6");
59                 }
60
61                 [Test]
62                 public void bug_82358 ()
63                 {
64                         //Console.WriteLine ("Starting bug_82358");
65                         int sizeable_factor;
66                         int title_bar;
67                         int tool_bar;
68                         int tool_border;
69                         int d3;
70                         int d2;
71
72                         // WinXP, default theme
73                         sizeable_factor = 2;
74                         title_bar = 26;
75                         tool_bar = 18;
76                         tool_border = 6;
77                         d3 = 10;
78                         d2 = 6;
79
80                         // WinXP, Win32 theme:
81                         sizeable_factor = 2;
82                         title_bar = 19;
83                         tool_bar = 16;
84                         tool_border = 6;
85                         d3 = 10;
86                         d2 = 6;
87
88
89                         Size size = new Size (200, 200);
90                         
91                         // Universal theme??
92                         using (Form f = new Form ()) {
93                                 f.FormBorderStyle = FormBorderStyle.FixedSingle;
94                                 f.Visible = true;
95                                 d2 = f.Size.Width - f.ClientSize.Width;
96                                 title_bar = f.Size.Height - f.ClientSize.Height - d2;
97                         }
98                         using (Form f = new Form ()) {
99                                 f.FormBorderStyle = FormBorderStyle.Sizable;
100                                 f.Visible = true;
101                                 sizeable_factor = f.Size.Width - f.ClientSize.Width - d2;
102                         }
103                         using (Form f = new Form ()) {
104                                 f.ClientSize = size;
105                                 f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
106                                 //f.Visible = true;
107                                 tool_border = f.Size.Width - f.ClientSize.Width;
108                                 tool_bar = f.Size.Height - f.ClientSize.Height - tool_border;
109                         }
110                         using (Form f = new Form ()) {
111                                 f.FormBorderStyle = FormBorderStyle.Fixed3D;
112                                 f.Visible = true;
113                                 d3 = f.Size.Width - f.ClientSize.Width; 
114                         }                       
115                 
116                         FormBorderStyle style;
117                         
118                         
119                         //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);
120                         
121                         // Changing client size, then FormBorderStyle.
122                         using (Form f = new Form ()) {
123                                 style = FormBorderStyle.FixedToolWindow;
124                                 //Console.WriteLine ("Created form, size: {0}, clientsize: {1}", f.Size, f.ClientSize);
125                                 f.ClientSize = size;
126                                 //Console.WriteLine ("Changed ClientSize, size: {0}, clientsize: {1}", f.Size, f.ClientSize);
127                                 f.FormBorderStyle = style;
128                                 //Console.WriteLine ("Changed FormBorderStyle, size: {0}, clientsize: {1}", f.Size, f.ClientSize);
129                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
130                                 Assert.AreEqual (new Size (size.Width + tool_border, size.Height + tool_border + tool_bar).ToString (), f.Size.ToString (), style.ToString () + "-A2");
131                                 f.Visible = true;
132                                 //Console.WriteLine ("Made visible, size: {0}, clientsize: {1}", f.Size, f.ClientSize);
133                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
134                                 Assert.AreEqual (new Size (size.Width + tool_border, size.Height + tool_border + tool_bar).ToString (), f.Size.ToString (), style.ToString () + "-A4");
135                         }
136
137                         using (Form f = new Form ()) {
138                                 style = FormBorderStyle.SizableToolWindow;
139                                 f.ClientSize = size;
140                                 f.FormBorderStyle = style;
141                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
142                                 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");
143                                 f.Visible = true;
144                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
145                                 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");
146                         }
147
148                         using (Form f = new Form ()) {
149                                 style = FormBorderStyle.Fixed3D;
150                                 f.ClientSize = size;
151                                 f.FormBorderStyle = style;
152                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
153                                 Assert.AreEqual (new Size (size.Width + d3, size.Height + title_bar + d3).ToString () , f.Size.ToString (), style.ToString () + "-A2");
154                                 f.Visible = true;
155                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
156                                 Assert.AreEqual (new Size (size.Width + d3, size.Height + title_bar + d3).ToString (), f.Size.ToString (), style.ToString () + "-A4");
157                         }
158
159                         using (Form f = new Form ()) {
160                                 style = FormBorderStyle.FixedDialog;
161                                 f.ClientSize = size;
162                                 f.FormBorderStyle = style;
163                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
164                                 Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-A2");
165                                 f.Visible = true;
166                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
167                                 Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-A4");
168                         
169                         }
170
171                         using (Form f = new Form ()) {
172                                 style = FormBorderStyle.FixedSingle;
173                                 f.ClientSize = size;
174                                 f.FormBorderStyle = style;
175                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
176                                 Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-A2");
177                                 f.Visible = true;
178                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
179                                 Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-A4");
180                         }
181
182                         using (Form f = new Form ()) {
183                                 style = FormBorderStyle.None;
184                                 f.ClientSize = size;
185                                 f.FormBorderStyle = style;
186                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
187                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-A2");
188                                 f.Visible = true;
189                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
190                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-A4");
191                         }
192
193                         using (Form f = new Form ()) {
194                                 style = FormBorderStyle.Sizable;
195                                 f.ClientSize = size;
196                                 f.FormBorderStyle = style;
197                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A1");
198                                 Assert.AreEqual (new Size (size.Width + d2 + sizeable_factor, size.Height + title_bar + d2 + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-A2");
199                                 f.Visible = true;
200                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
201                                 Assert.AreEqual (new Size (size.Width + d2 + sizeable_factor, size.Height + title_bar + d2 + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-A4");
202                         }
203                         
204                         
205                         // Changing size, then FormBorderStyle.
206                         using (Form f = new Form ()) {
207                                 style = FormBorderStyle.FixedToolWindow;
208                                 f.Size = size;
209                                 f.FormBorderStyle = style;
210                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
211                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
212                                 f.Visible = true;
213                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
214                                 Assert.AreEqual (new Size (size.Width - tool_border, size.Height - tool_border - tool_bar).ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
215                         }
216
217                         using (Form f = new Form ()) {
218                                 style = FormBorderStyle.SizableToolWindow;
219                                 f.Size = size;
220                                 f.FormBorderStyle = style;
221                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
222                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
223                                 f.Visible = true;
224                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
225                                 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");
226                         }
227
228                         using (Form f = new Form ()) {
229                                 style = FormBorderStyle.Fixed3D;
230                                 f.Size = size;
231                                 f.FormBorderStyle = style;
232                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
233                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
234                                 f.Visible = true;
235                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
236                                 Assert.AreEqual (new Size (size.Width - d3, size.Height - title_bar - d3).ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
237                         }
238
239                         using (Form f = new Form ()) {
240                                 style = FormBorderStyle.FixedDialog;
241                                 f.Size = size;
242                                 f.FormBorderStyle = style;
243                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
244                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
245                                 f.Visible = true;
246                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
247                                 Assert.AreEqual (new Size (size.Width - d2, size.Height - title_bar - d2).ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
248
249                         }
250
251                         using (Form f = new Form ()) {
252                                 style = FormBorderStyle.FixedSingle;
253                                 f.Size = size;
254                                 f.FormBorderStyle = style;
255                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
256                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
257                                 f.Visible = true;
258                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
259                                 Assert.AreEqual (new Size (size.Width - d2, size.Height - title_bar - d2).ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
260                         }
261
262                         using (Form f = new Form ()) {
263                                 style = FormBorderStyle.None;
264                                 f.Size = size;
265                                 f.FormBorderStyle = style;
266                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
267                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
268                                 f.Visible = true;
269                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
270                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
271                         }
272
273                         using (Form f = new Form ()) {
274                                 style = FormBorderStyle.Sizable;
275                                 f.Size = size;
276                                 f.FormBorderStyle = style;
277                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B1");
278                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B2");
279                                 f.Visible = true;
280                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
281                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
282                         }
283
284
285
286                         // Changing FormBorderStyle, then client size
287                         using (Form f = new Form ()) {
288                                 style = FormBorderStyle.FixedToolWindow;
289                                 f.FormBorderStyle = style;
290                                 f.ClientSize = size;
291                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
292                                 Assert.AreEqual (new Size (size.Width + tool_border, size.Height + tool_border + tool_bar).ToString (), f.Size.ToString (), style.ToString () + "-C2");
293                                 f.Visible = true;
294                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
295                                 Assert.AreEqual (new Size (size.Width + tool_border, size.Height + tool_border + tool_bar).ToString (), f.Size.ToString (), style.ToString () + "-C4");
296                         }
297
298                         using (Form f = new Form ()) {
299                                 style = FormBorderStyle.SizableToolWindow;
300                                 f.FormBorderStyle = style;
301                                 f.ClientSize = size;
302                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
303                                 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");
304                                 f.Visible = true;
305                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
306                                 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");
307                         }
308
309                         using (Form f = new Form ()) {
310                                 style = FormBorderStyle.Fixed3D;
311                                 f.FormBorderStyle = style;
312                                 f.ClientSize = size;
313                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
314                                 Assert.AreEqual (new Size (size.Width + d3, size.Height + title_bar + d3).ToString (), f.Size.ToString (), style.ToString () + "-C2");
315                                 f.Visible = true;
316                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
317                                 Assert.AreEqual (new Size (size.Width + d3, size.Height + title_bar + d3).ToString (), f.Size.ToString (), style.ToString () + "-C4");
318                         }
319
320                         using (Form f = new Form ()) {
321                                 style = FormBorderStyle.FixedDialog;
322                                 f.FormBorderStyle = style;
323                                 f.ClientSize = size;
324                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
325                                 Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-C2");
326                                 f.Visible = true;
327                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
328                                 Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-C4");
329
330                         }
331
332                         using (Form f = new Form ()) {
333                                 style = FormBorderStyle.FixedSingle;
334                                 f.FormBorderStyle = style;
335                                 f.ClientSize = size;
336                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
337                                 Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-C2");
338                                 f.Visible = true;
339                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
340                                 Assert.AreEqual (new Size (size.Width + d2, size.Height + title_bar + d2).ToString (), f.Size.ToString (), style.ToString () + "-C4");
341                         }
342
343                         using (Form f = new Form ()) {
344                                 style = FormBorderStyle.None;
345                                 f.FormBorderStyle = style;
346                                 f.ClientSize = size;
347                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
348                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-C2");
349                                 f.Visible = true;
350                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
351                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-C4");
352                         }
353
354                         using (Form f = new Form ()) {
355                                 style = FormBorderStyle.Sizable;
356                                 f.FormBorderStyle = style;
357                                 f.ClientSize = size;
358                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
359                                 Assert.AreEqual (new Size (size.Width + d2 + sizeable_factor, size.Height + title_bar + d2 + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-C2");
360                                 f.Visible = true;
361                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
362                                 Assert.AreEqual (new Size (size.Width + d2 + sizeable_factor, size.Height + title_bar + d2 + sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-C4");
363                         }
364
365
366                         // Changing FormBorderStyle, then size
367                         using (Form f = new Form ()) {
368                                 style = FormBorderStyle.FixedToolWindow;
369                                 f.FormBorderStyle = style;
370                                 f.Size = size;
371                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D1");
372                                 Assert.AreEqual (new Size (size.Width - tool_border, size.Height - tool_border - tool_bar).ToString (), f.ClientSize.ToString (), style.ToString () + "-D2");
373                                 f.Visible = true;
374                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D3");
375                                 Assert.AreEqual (new Size (size.Width - tool_border, size.Height - tool_border - tool_bar).ToString (), f.ClientSize.ToString (), style.ToString () + "-D4");
376                         }
377
378                         using (Form f = new Form ()) {
379                                 style = FormBorderStyle.SizableToolWindow;
380                                 f.FormBorderStyle = style;
381                                 f.Size = size;
382                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D1");
383                                 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");
384                                 f.Visible = true;
385                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D3");
386                                 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");
387                         }
388
389                         using (Form f = new Form ()) {
390                                 style = FormBorderStyle.Fixed3D;
391                                 f.FormBorderStyle = style;
392                                 f.Size = size;
393                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D1");
394                                 Assert.AreEqual (new Size (size.Width - d3, size.Height - title_bar - d3).ToString (), f.ClientSize.ToString (), style.ToString () + "-D2");
395                                 f.Visible = true;
396                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D3");
397                                 Assert.AreEqual (new Size (size.Width - d3, size.Height - title_bar - d3).ToString (), f.ClientSize.ToString (), style.ToString () + "-D4");
398                         }
399
400                         using (Form f = new Form ()) {
401                                 style = FormBorderStyle.FixedDialog;
402                                 f.FormBorderStyle = style;
403                                 f.Size = size;
404                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D1");
405                                 Assert.AreEqual (new Size (size.Width - d2, size.Height - title_bar - d2).ToString (), f.ClientSize.ToString (), style.ToString () + "-D2");
406                                 f.Visible = true;
407                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D3");
408                                 Assert.AreEqual (new Size (size.Width - d2, size.Height - title_bar - d2).ToString (), f.ClientSize.ToString (), style.ToString () + "-D4");
409
410                         }
411
412                         using (Form f = new Form ()) {
413                                 style = FormBorderStyle.FixedSingle;
414                                 f.FormBorderStyle = style;
415                                 f.Size = size;
416                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D1");
417                                 Assert.AreEqual (new Size (size.Width - d2, size.Height - title_bar - d2).ToString (), f.ClientSize.ToString (), style.ToString () + "-D2");
418                                 f.Visible = true;
419                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D3");
420                                 Assert.AreEqual (new Size (size.Width - d2, size.Height - title_bar - d2).ToString (), f.ClientSize.ToString (), style.ToString () + "-D4");
421                         }
422
423                         using (Form f = new Form ()) {
424                                 style = FormBorderStyle.None;
425                                 f.FormBorderStyle = style;
426                                 f.Size = size;
427                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-D1");
428                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D2");
429                                 f.Visible = true;
430                                 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-D3");
431                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D4");
432                         }
433
434                         using (Form f = new Form ()) {
435                                 style = FormBorderStyle.Sizable;
436                                 f.FormBorderStyle = style;
437                                 f.Size = size;
438                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D1");
439                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-D2");
440                                 f.Visible = true;
441                                 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D3");
442                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-D4");
443                         }
444
445
446
447                         // Set clientsize, then change size, then FormBorderStyle.
448                         using (Form f = new Form ()) {
449                                 style = FormBorderStyle.FixedToolWindow;
450                                 f.ClientSize = f.ClientSize;
451                                 f.Size = size;
452                                 f.FormBorderStyle = style;
453                                 // Here we subtract the Sizable borders (default) then add FixedToolWindow's border.
454                                 // Note how now the sizes doesn't change when creating the handle.
455                                 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");
456                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
457                                 f.Visible = true;
458                                 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");
459                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
460                         }
461
462                         using (Form f = new Form ()) {
463                                 style = FormBorderStyle.SizableToolWindow;
464                                 f.ClientSize = f.ClientSize;
465                                 f.Size = size;
466                                 f.FormBorderStyle = style;
467                                 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");
468                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
469                                 f.Visible = true;
470                                 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");
471                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
472                         }
473
474                         using (Form f = new Form ()) {
475                                 style = FormBorderStyle.Fixed3D;
476                                 f.ClientSize = f.ClientSize;
477                                 f.Size = size;
478                                 f.FormBorderStyle = style;
479                                 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");
480                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
481                                 f.Visible = true;
482                                 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");
483                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
484                         }
485
486                         using (Form f = new Form ()) {
487                                 style = FormBorderStyle.FixedDialog;
488                                 f.ClientSize = f.ClientSize;
489                                 f.Size = size;
490                                 f.FormBorderStyle = style;
491                                 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");
492                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
493                                 f.Visible = true;
494                                 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");
495                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
496
497                         }
498
499                         using (Form f = new Form ()) {
500                                 style = FormBorderStyle.FixedSingle;
501                                 f.ClientSize = f.ClientSize;
502                                 f.Size = size;
503                                 f.FormBorderStyle = style;
504                                 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");
505                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
506                                 f.Visible = true;
507                                 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");
508                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
509                         }
510
511                         using (Form f = new Form ()) {
512                                 style = FormBorderStyle.None;
513                                 f.ClientSize = f.ClientSize;
514                                 f.Size = size;
515                                 f.FormBorderStyle = style;
516                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-E1");
517                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
518                                 f.Visible = true;
519                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.Size.ToString (), style.ToString () + "-E3");
520                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
521                         }
522
523                         using (Form f = new Form ()) {
524                                 style = FormBorderStyle.Sizable;
525                                 f.ClientSize = f.ClientSize;
526                                 f.Size = size;
527                                 f.FormBorderStyle = style;
528                                 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");
529                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E2");
530                                 f.Visible = true;
531                                 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");
532                                 Assert.AreEqual (new Size (size.Width - d2 - sizeable_factor, size.Height - title_bar - d2 - sizeable_factor).ToString (), f.ClientSize.ToString (), style.ToString () + "-E4");
533                         }
534
535
536
537
538                 }
539
540                 [Test] // bug 81969
541                 public void StartPositionClosedForm ()
542                 {
543                         using (Form form = new Form ()) {
544                                 form.StartPosition = FormStartPosition.CenterParent;
545                                 form.Load += new EventHandler (CenterDisposedForm_Load);
546                                 form.Show ();
547                         }
548
549                         using (Form form = new Form ()) {
550                                 form.StartPosition = FormStartPosition.CenterScreen;
551                                 form.Load += new EventHandler (CenterDisposedForm_Load);
552                                 form.Show ();
553                         }
554
555
556                         using (Form form = new Form ()) {
557                                 form.StartPosition = FormStartPosition.Manual;
558                                 form.Load += new EventHandler (CenterDisposedForm_Load);
559                                 form.Show ();
560                         }
561
562
563                         using (Form form = new Form ()) {
564                                 form.StartPosition = FormStartPosition.WindowsDefaultBounds;
565                                 form.Load += new EventHandler (CenterDisposedForm_Load);
566                                 form.Show ();
567                         }
568
569                         using (Form form = new Form ()) {
570                                 form.StartPosition = FormStartPosition.WindowsDefaultLocation;
571                                 form.Load += new EventHandler (CenterDisposedForm_Load);
572                                 form.Show ();
573                         }
574                 }
575                 
576                 
577                 [Test] 
578                 [ExpectedException (typeof (ObjectDisposedException))]
579                 public void CenterToParentDisposedForm ()
580                 {
581                         using (FormHandleTest.ProtectedMethodsForm form = new FormHandleTest.ProtectedMethodsForm ()) {
582                                 form.Dispose ();
583                                 form.PublicCenterToParent ();
584                         }
585                 }
586
587                 [Test]
588                 [ExpectedException (typeof (ObjectDisposedException))]
589                 public void CenterToScreenDisposedForm ()
590                 {
591                         using (FormHandleTest.ProtectedMethodsForm form = new FormHandleTest.ProtectedMethodsForm ()) {
592                                 form.Dispose ();
593                                 form.PublicCenterToScreen ();
594                         }
595                 }
596
597                 [Test]
598                 public void SetStartPositionDisposedForm ()
599                 {
600                         using (FormHandleTest.ProtectedMethodsForm form = new FormHandleTest.ProtectedMethodsForm ()) {
601                                 form.Dispose ();
602                                 form.StartPosition = FormStartPosition.WindowsDefaultLocation;
603                         }
604                 }
605
606                 private void CenterDisposedForm_Load (object sender, EventArgs e)
607                 {
608                         ((Form) sender).Close ();
609                 }
610
611                 [Test]
612                 public void ShowDialogCloseTest ()
613                 {
614                         using (TimeBombedForm f = new TimeBombedForm ()) {
615                                 EventLogger log = new EventLogger (f);
616                                 f.timer.Interval = 1000;
617                                 f.VisibleChanged += new EventHandler (Form_VisibleChanged1);
618                                 f.ShowDialog ();
619                                 
620                                 Assert.AreEqual ("VisibleChanged", f.Reason, "#00");
621                                 Assert.AreEqual (1, log.CountEvents ("Closing"), "#01");
622 #if NET_2_0
623                                 Assert.AreEqual (1, log.CountEvents ("FormClosing"), "#02");
624 #endif
625                                 Assert.AreEqual (1, log.CountEvents ("HandleDestroyed"), "#03");
626
627                                 Assert.AreEqual (0, log.CountEvents ("Closed"), "#04");
628 #if NET_2_0
629                                 Assert.AreEqual (0, log.CountEvents ("FormClosed"), "#05");
630 #endif
631                                 Assert.AreEqual (0, log.CountEvents ("Disposed"), "#06");
632                         }
633
634                         using (TimeBombedForm f = new TimeBombedForm ()) {
635                                 EventLogger log = new EventLogger (f);
636                                 f.ShowDialog ();
637
638                                 Assert.AreEqual ("Bombed", f.Reason, "#A0");
639                                 Assert.AreEqual (1, log.CountEvents ("Closing"), "#A1");
640 #if NET_2_0
641                                 Assert.AreEqual (1, log.CountEvents ("FormClosing"), "#A2");
642 #endif
643                                 Assert.AreEqual (1, log.CountEvents ("HandleDestroyed"), "#A3");
644
645                                 Assert.AreEqual (1, log.CountEvents ("Closed"), "#A4");
646 #if NET_2_0
647                                 Assert.AreEqual (1, log.CountEvents ("FormClosed"), "#A5");
648 #endif
649                                 Assert.AreEqual (0, log.CountEvents ("Disposed"), "#A6");
650                         }
651
652
653                         using (TimeBombedForm f = new TimeBombedForm ()) {
654                                 EventLogger log = new EventLogger (f);
655                                 f.VisibleChanged += new EventHandler (Form_VisibleChanged2);
656                                 f.ShowDialog ();
657
658                                 Assert.AreEqual ("VisibleChanged", f.Reason, "#B0");
659 #if NET_2_0
660                                 Assert.AreEqual (1, log.CountEvents ("Closing"), "#B1");
661                                 Assert.AreEqual (1, log.CountEvents ("FormClosing"), "#B2");
662 #endif
663                                 Assert.AreEqual (1, log.CountEvents ("HandleDestroyed"), "#B3");
664
665 #if NET_2_0
666                                 Assert.AreEqual (1, log.CountEvents ("Closed"), "#B4");
667                                 Assert.AreEqual (1, log.CountEvents ("FormClosed"), "#B5");
668 #endif
669                                 Assert.AreEqual (0, log.CountEvents ("Disposed"), "#B6");
670                         }
671
672
673                         using (TimeBombedForm f = new TimeBombedForm ()) {
674                                 EventLogger log = new EventLogger (f);
675                                 f.DialogResult = DialogResult.None;
676                                 f.ShowDialog ();
677
678                                 Assert.AreEqual ("Bombed", f.Reason, "#C0");
679                                 Assert.AreEqual (1, log.CountEvents ("Closing"), "#C1");
680 #if NET_2_0
681                                 Assert.AreEqual (1, log.CountEvents ("FormClosing"), "#C2");
682 #endif
683                                 Assert.AreEqual (1, log.CountEvents ("HandleDestroyed"), "#C3");
684
685                                 Assert.AreEqual (1, log.CountEvents ("Closed"), "#C4");
686 #if NET_2_0
687                                 Assert.AreEqual (1, log.CountEvents ("FormClosed"), "#C5");
688 #endif
689                                 Assert.AreEqual (0, log.CountEvents ("Disposed"), "#C6");
690                                 
691                                 Assert.AreEqual (DialogResult.Cancel, f.DialogResult, "#C7");
692                         }
693                 }
694
695                 void Form_VisibleChanged1 (object sender, EventArgs e)
696                 {
697                         TimeBombedForm f = (TimeBombedForm) sender;
698                         f.Reason = "VisibleChanged";
699                         f.Visible = false;
700                 }
701
702                 void Form_VisibleChanged2 (object sender, EventArgs e)
703                 {
704                         TimeBombedForm f = (TimeBombedForm) sender;
705                         f.Reason = "VisibleChanged";
706                         f.Visible = false;
707                         f.DialogResult = DialogResult.OK;
708                         Assert.IsFalse (f.Visible);
709                 }
710
711                 [Test]
712                 public void DialogOwnerTest ()
713                 {
714                         using (Form first = new Form ()) {
715                                 using (TimeBombedForm second = new TimeBombedForm ()) {
716                                         first.Show ();
717                                         second.Load += new EventHandler (second_Load);
718                                         second.ShowDialog ();
719                                 }
720                         }
721                 }
722
723                 void second_Load (object sender, EventArgs e)
724                 {
725                         Form second = (Form) sender;
726                         Assert.IsNull (second.Owner, "#1");
727                 }
728                 
729                 [Test]
730                 [Category ("NotWorking")]
731                 public void FormStartupPositionChangeTest ()
732                 {
733                         using (Form frm = new Form ())
734                         {
735                                 frm.ShowInTaskbar = false;
736                                 frm.StartPosition = FormStartPosition.Manual;
737                                 frm.Location = new Point (0, 0);
738                                 frm.Show ();
739
740                                 // On X there seem to be pending messages in the queue aren't processed
741                                 // before Show returns, so process them. Otherwise the Location returns
742                                 // something like (5,23)
743                                 Application.DoEvents ();
744                                 
745                                 Assert.AreEqual ("{X=0,Y=0}", frm.Location.ToString (), "#01");
746
747                                 frm.StartPosition = FormStartPosition.CenterParent;
748                                 Assert.AreEqual ("{X=0,Y=0}", frm.Location.ToString (), "#02");
749
750                                 frm.StartPosition = FormStartPosition.CenterScreen;
751                                 Assert.AreEqual ("{X=0,Y=0}", frm.Location.ToString (), "#03");
752
753                                 frm.StartPosition = FormStartPosition.Manual;
754                                 Assert.AreEqual ("{X=0,Y=0}", frm.Location.ToString (), "#04");
755
756                                 frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
757                                 Assert.AreEqual ("{X=0,Y=0}", frm.Location.ToString (), "#05");
758
759                                 frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
760                                 Assert.AreEqual ("{X=0,Y=0}", frm.Location.ToString (), "#06");
761                         }
762                 }
763                 
764                 [Test]
765                 public void FormStartupPositionTest ()
766                 {
767                         CreateParams cp;
768                         
769                         using (Form frm = new Form ())
770                         {
771                                 cp = TestHelper.GetCreateParams (frm);
772                                 Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$01");
773                                 Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#01");
774
775                                 frm.StartPosition = FormStartPosition.CenterParent;
776                                 cp = TestHelper.GetCreateParams (frm);
777                                 Assert.AreEqual (FormStartPosition.CenterParent, frm.StartPosition, "$01");
778                                 Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#02");
779
780                                 frm.StartPosition = FormStartPosition.CenterScreen;
781                                 cp = TestHelper.GetCreateParams (frm);
782                                 Assert.AreEqual (FormStartPosition.CenterScreen, frm.StartPosition, "$01");
783                                 Assert.AreEqual (new Point (Screen.PrimaryScreen.WorkingArea.Width / 2 - frm.Width / 2, Screen.PrimaryScreen.WorkingArea.Height / 2 - frm.Height / 2).ToString (), new Point (cp.X, cp.Y).ToString (), "#03");
784
785                                 frm.StartPosition = FormStartPosition.Manual;
786                                 cp = TestHelper.GetCreateParams (frm);
787                                 Assert.AreEqual (FormStartPosition.Manual, frm.StartPosition, "$01");
788                                 Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#04");
789
790                                 frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
791                                 cp = TestHelper.GetCreateParams (frm);
792                                 Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, frm.StartPosition, "$01");
793                                 Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#05");
794
795                                 frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
796                                 cp = TestHelper.GetCreateParams (frm);
797                                 Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$01");
798                                 Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#06");
799                                 
800                         }
801
802
803                         using (Form frm = new Form ()) {
804                                 frm.Location = new Point (23, 45);
805
806                                 cp = TestHelper.GetCreateParams (frm);
807                                 Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$A1");
808                                 Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#A1");
809
810                                 frm.StartPosition = FormStartPosition.CenterParent;
811                                 cp = TestHelper.GetCreateParams (frm);
812                                 Assert.AreEqual (FormStartPosition.CenterParent, frm.StartPosition, "$A2");
813                                 Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#A2");
814
815                                 frm.StartPosition = FormStartPosition.CenterScreen;
816                                 cp = TestHelper.GetCreateParams (frm);
817                                 Assert.AreEqual (FormStartPosition.CenterScreen, frm.StartPosition, "$A3");
818                                 Assert.AreEqual (new Point (Screen.PrimaryScreen.WorkingArea.Width / 2 - frm.Width / 2, Screen.PrimaryScreen.WorkingArea.Height / 2 - frm.Height / 2).ToString (), new Point (cp.X, cp.Y).ToString (), "#A3");
819
820                                 frm.StartPosition = FormStartPosition.Manual;
821                                 cp = TestHelper.GetCreateParams (frm);
822                                 Assert.AreEqual (FormStartPosition.Manual, frm.StartPosition, "$A4");
823                                 Assert.AreEqual (new Point (23, 45).ToString (), new Point (cp.X, cp.Y).ToString (), "#A4");
824
825                                 frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
826                                 cp = TestHelper.GetCreateParams (frm);
827                                 Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, frm.StartPosition, "$A5");
828                                 Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#A5");
829
830                                 frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
831                                 cp = TestHelper.GetCreateParams (frm);
832                                 Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$A6");
833                                 Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#A6");
834                         }
835                 }
836                 
837                 [Test]
838                 public void MdiFormStartupPositionTest ()
839                 {
840                         CreateParams cp;
841                         using (Form Main = new Form ()) {
842                                 Main.IsMdiContainer = true;
843                                 Main.ShowInTaskbar = false;
844                                 Main.Show ();
845                                 
846                                 using (Form frm = new Form ()) {
847                                         frm.MdiParent = Main;
848                                         cp = TestHelper.GetCreateParams (frm);
849                                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$01");
850                                         Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#01");
851
852                                         frm.StartPosition = FormStartPosition.CenterParent;
853                                         cp = TestHelper.GetCreateParams (frm);
854                                         Assert.AreEqual (FormStartPosition.CenterParent, frm.StartPosition, "$01");
855                                         Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#02");
856
857                                         frm.StartPosition = FormStartPosition.CenterScreen;
858                                         cp = TestHelper.GetCreateParams (frm);
859                                         Assert.AreEqual (FormStartPosition.CenterScreen, frm.StartPosition, "$01");
860                                         Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#03");
861
862                                         frm.StartPosition = FormStartPosition.Manual;
863                                         cp = TestHelper.GetCreateParams (frm);
864                                         Assert.AreEqual (FormStartPosition.Manual, frm.StartPosition, "$01");
865                                         Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#04");
866
867                                         frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
868                                         cp = TestHelper.GetCreateParams (frm);
869                                         Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, frm.StartPosition, "$01");
870                                         Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#05");
871
872                                         frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
873                                         cp = TestHelper.GetCreateParams (frm);
874                                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$01");
875                                         Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#06");
876                                         frm.Show ();
877                                 }
878
879                                 using (Form frm = new Form ()) {
880                                         frm.MdiParent = Main;
881                                         frm.Location = new Point (23, 45);
882
883                                         cp = TestHelper.GetCreateParams (frm);
884                                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$A1");
885                                         Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#A1");
886
887                                         frm.StartPosition = FormStartPosition.CenterParent;
888                                         cp = TestHelper.GetCreateParams (frm);
889                                         Assert.AreEqual (FormStartPosition.CenterParent, frm.StartPosition, "$A2");
890                                         Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#A2");
891
892                                         frm.StartPosition = FormStartPosition.CenterScreen;
893                                         cp = TestHelper.GetCreateParams (frm);
894                                         Assert.AreEqual (FormStartPosition.CenterScreen, frm.StartPosition, "$A3");
895                                         Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#A3");
896
897                                         frm.StartPosition = FormStartPosition.Manual;
898                                         cp = TestHelper.GetCreateParams (frm);
899                                         Assert.AreEqual (FormStartPosition.Manual, frm.StartPosition, "$A4");
900                                         Assert.AreEqual (new Point (23, 45).ToString (), new Point (cp.X, cp.Y).ToString (), "#A4");
901
902                                         frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
903                                         cp = TestHelper.GetCreateParams (frm);
904                                         Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, frm.StartPosition, "$A5");
905                                         Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#A5");
906
907                                         frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
908                                         cp = TestHelper.GetCreateParams (frm);
909                                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$A6");
910                                         Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#A6");
911
912                                         frm.Show ();
913                                 }
914
915                                 using (Form frm = new Form ()) {
916                                         frm.MdiParent = Main;
917                                         frm.Location = new Point (34, 56);
918
919                                         cp = TestHelper.GetCreateParams (frm);
920                                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$B1");
921                                         Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#B1");
922
923                                         frm.StartPosition = FormStartPosition.CenterParent;
924                                         cp = TestHelper.GetCreateParams (frm);
925                                         Assert.AreEqual (FormStartPosition.CenterParent, frm.StartPosition, "$B2");
926                                         Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#B2");
927
928                                         frm.StartPosition = FormStartPosition.CenterScreen;
929                                         cp = TestHelper.GetCreateParams (frm);
930                                         Assert.AreEqual (FormStartPosition.CenterScreen, frm.StartPosition, "$B3");
931                                         Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#B3");
932
933                                         frm.StartPosition = FormStartPosition.Manual;
934                                         cp = TestHelper.GetCreateParams (frm);
935                                         Assert.AreEqual (FormStartPosition.Manual, frm.StartPosition, "$B4");
936                                         Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#B4");
937
938                                         frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
939                                         cp = TestHelper.GetCreateParams (frm);
940                                         Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, frm.StartPosition, "$B5");
941                                         Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#B5");
942
943                                         frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
944                                         cp = TestHelper.GetCreateParams (frm);
945                                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$B6");
946                                         Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#B6");
947
948                                         frm.Show ();
949                                 }
950
951                                 Main.Size = new Size (600, 600);
952                                 using (Form frm = new Form ()) {
953                                         frm.MdiParent = Main;
954                                         frm.Location = new Point (34, 56);
955
956                                         cp = TestHelper.GetCreateParams (frm);
957                                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$C1");
958                                         Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#C1");
959
960                                         frm.StartPosition = FormStartPosition.CenterParent;
961                                         cp = TestHelper.GetCreateParams (frm);
962                                         Assert.AreEqual (FormStartPosition.CenterParent, frm.StartPosition, "$C2");
963                                         Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#C2");
964
965                                         frm.StartPosition = FormStartPosition.CenterScreen;
966                                         cp = TestHelper.GetCreateParams (frm);
967                                         Assert.AreEqual (FormStartPosition.CenterScreen, frm.StartPosition, "$C3");
968                                         Assert.AreEqual (new Point (Main.Controls [0].ClientSize.Width / 2 - frm.Width / 2, Main.Controls [0].ClientSize.Height / 2 - frm.Height / 2).ToString (), new Point (cp.X, cp.Y).ToString (), "#C3");
969
970                                         frm.StartPosition = FormStartPosition.Manual;
971                                         cp = TestHelper.GetCreateParams (frm);
972                                         Assert.AreEqual (FormStartPosition.Manual, frm.StartPosition, "$C4");
973                                         Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#C4");
974
975                                         frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
976                                         cp = TestHelper.GetCreateParams (frm);
977                                         Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, frm.StartPosition, "$C5");
978                                         Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#C5");
979
980                                         frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
981                                         cp = TestHelper.GetCreateParams (frm);
982                                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$C6");
983                                         Assert.AreEqual (new Point (int.MinValue, int.MinValue).ToString (), new Point (cp.X, cp.Y).ToString (), "#C6");
984
985                                         frm.Show ();
986                                 }
987                         }
988                 }
989
990                 [Test]
991                 public void ParentedFormStartupPositionTest ()
992                 {
993                         CreateParams cp;
994                         using (Form Main = new Form ()) {
995                                 Main.ShowInTaskbar = false;
996                                 Main.Show ();
997
998                                 using (Form frm = new Form ()) {
999                                         frm.TopLevel = false;
1000                                         Main.Controls.Add (frm);
1001                                         cp = TestHelper.GetCreateParams (frm);
1002                                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$01");
1003                                         Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#01");
1004
1005                                         frm.StartPosition = FormStartPosition.CenterParent;
1006                                         cp = TestHelper.GetCreateParams (frm);
1007                                         Assert.AreEqual (FormStartPosition.CenterParent, frm.StartPosition, "$02");
1008                                         Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#02");
1009
1010                                         frm.StartPosition = FormStartPosition.CenterScreen;
1011                                         cp = TestHelper.GetCreateParams (frm);
1012                                         Assert.AreEqual (FormStartPosition.CenterScreen, frm.StartPosition, "$03");
1013                                         Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#03");
1014
1015                                         frm.StartPosition = FormStartPosition.Manual;
1016                                         cp = TestHelper.GetCreateParams (frm);
1017                                         Assert.AreEqual (FormStartPosition.Manual, frm.StartPosition, "$04");
1018                                         Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#04");
1019
1020                                         frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
1021                                         cp = TestHelper.GetCreateParams (frm);
1022                                         Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, frm.StartPosition, "$05");
1023                                         Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#05");
1024
1025                                         frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
1026                                         cp = TestHelper.GetCreateParams (frm);
1027                                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$06");
1028                                         Assert.AreEqual (new Point (0, 0).ToString (), new Point (cp.X, cp.Y).ToString (), "#06");
1029                                         frm.Show ();
1030                                 }
1031
1032                                 using (Form frm = new Form ()) {
1033                                         frm.TopLevel = false;
1034                                         Main.Controls.Add (frm);
1035                                         frm.Location = new Point (23, 45);
1036
1037                                         cp = TestHelper.GetCreateParams (frm);
1038                                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$A1");
1039                                         Assert.AreEqual (new Point (23, 45).ToString (), new Point (cp.X, cp.Y).ToString (), "#A1");
1040
1041                                         frm.StartPosition = FormStartPosition.CenterParent;
1042                                         cp = TestHelper.GetCreateParams (frm);
1043                                         Assert.AreEqual (FormStartPosition.CenterParent, frm.StartPosition, "$A2");
1044                                         Assert.AreEqual (new Point (23, 45).ToString (), new Point (cp.X, cp.Y).ToString (), "#A2");
1045
1046                                         frm.StartPosition = FormStartPosition.CenterScreen;
1047                                         cp = TestHelper.GetCreateParams (frm);
1048                                         Assert.AreEqual (FormStartPosition.CenterScreen, frm.StartPosition, "$A3");
1049                                         Assert.AreEqual (new Point (23, 45).ToString (), new Point (cp.X, cp.Y).ToString (), "#A3");
1050
1051                                         frm.StartPosition = FormStartPosition.Manual;
1052                                         cp = TestHelper.GetCreateParams (frm);
1053                                         Assert.AreEqual (FormStartPosition.Manual, frm.StartPosition, "$A4");
1054                                         Assert.AreEqual (new Point (23, 45).ToString (), new Point (cp.X, cp.Y).ToString (), "#A4");
1055
1056                                         frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
1057                                         cp = TestHelper.GetCreateParams (frm);
1058                                         Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, frm.StartPosition, "$A5");
1059                                         Assert.AreEqual (new Point (23, 45).ToString (), new Point (cp.X, cp.Y).ToString (), "#A5");
1060
1061                                         frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
1062                                         cp = TestHelper.GetCreateParams (frm);
1063                                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$A6");
1064                                         Assert.AreEqual (new Point (23, 45).ToString (), new Point (cp.X, cp.Y).ToString (), "#A6");
1065
1066                                         frm.Show ();
1067                                 }
1068
1069                                 using (Form frm = new Form ()) {
1070                                         frm.TopLevel = false;
1071                                         Main.Controls.Add (frm);
1072                                         frm.Location = new Point (34, 56);
1073
1074                                         cp = TestHelper.GetCreateParams (frm);
1075                                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$B1");
1076                                         Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#B1");
1077
1078                                         frm.StartPosition = FormStartPosition.CenterParent;
1079                                         cp = TestHelper.GetCreateParams (frm);
1080                                         Assert.AreEqual (FormStartPosition.CenterParent, frm.StartPosition, "$B2");
1081                                         Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#B2");
1082
1083                                         frm.StartPosition = FormStartPosition.CenterScreen;
1084                                         cp = TestHelper.GetCreateParams (frm);
1085                                         Assert.AreEqual (FormStartPosition.CenterScreen, frm.StartPosition, "$B3");
1086                                         Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#B3");
1087
1088                                         frm.StartPosition = FormStartPosition.Manual;
1089                                         cp = TestHelper.GetCreateParams (frm);
1090                                         Assert.AreEqual (FormStartPosition.Manual, frm.StartPosition, "$B4");
1091                                         Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#B4");
1092
1093                                         frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
1094                                         cp = TestHelper.GetCreateParams (frm);
1095                                         Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, frm.StartPosition, "$B5");
1096                                         Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#B5");
1097
1098                                         frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
1099                                         cp = TestHelper.GetCreateParams (frm);
1100                                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$B6");
1101                                         Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#B6");
1102
1103                                         frm.Show ();
1104                                 }
1105
1106                                 Main.Size = new Size (600, 600);
1107                                 using (Form frm = new Form ()) {
1108                                         frm.TopLevel = false;
1109                                         Main.Controls.Add (frm);
1110                                         frm.Location = new Point (34, 56);
1111
1112                                         cp = TestHelper.GetCreateParams (frm);
1113                                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$C1");
1114                                         Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#C1");
1115
1116                                         frm.StartPosition = FormStartPosition.CenterParent;
1117                                         cp = TestHelper.GetCreateParams (frm);
1118                                         Assert.AreEqual (FormStartPosition.CenterParent, frm.StartPosition, "$C2");
1119                                         Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#C2");
1120
1121                                         frm.StartPosition = FormStartPosition.CenterScreen;
1122                                         cp = TestHelper.GetCreateParams (frm);
1123                                         Assert.AreEqual (FormStartPosition.CenterScreen, frm.StartPosition, "$C3");
1124                                         Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#C3");
1125
1126                                         frm.StartPosition = FormStartPosition.Manual;
1127                                         cp = TestHelper.GetCreateParams (frm);
1128                                         Assert.AreEqual (FormStartPosition.Manual, frm.StartPosition, "$C4");
1129                                         Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#C4");
1130
1131                                         frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
1132                                         cp = TestHelper.GetCreateParams (frm);
1133                                         Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, frm.StartPosition, "$C5");
1134                                         Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#C5");
1135
1136                                         frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
1137                                         cp = TestHelper.GetCreateParams (frm);
1138                                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, frm.StartPosition, "$C6");
1139                                         Assert.AreEqual (new Point (34, 56).ToString (), new Point (cp.X, cp.Y).ToString (), "#C6");
1140
1141                                         frm.Show ();
1142                                 }
1143                         }
1144                 }
1145                 
1146                 [Test]
1147                 public void UnparentForm ()
1148                 {
1149                         Form f1 = new Form ();
1150                         f1.Show ();
1151
1152                         Form f2 = new Form ();
1153                         f2.TopLevel = false;
1154                         f2.Parent = f1;
1155                         Assert.AreSame (f1, f2.Parent, "#1");
1156                         f2.Show ();
1157                         f2.Parent = null;
1158                         Assert.IsNull (f2.Parent, "#2");
1159                 }
1160
1161                 [Test] // bug #80791
1162                 public void ClientSizeTest ()
1163                 {
1164                         Form form = new Form ();
1165                         Assert.IsFalse (form.ClientSize == form.Size);
1166                 }
1167
1168                 [Test] // bug #80574
1169                 [Category ("NotWorking")]
1170                 public void FormBorderStyleTest ()
1171                 {
1172                         Form form = new Form ();
1173                         Rectangle boundsBeforeBorderStyleChange = form.Bounds;
1174                         Rectangle clientRectangleBeforeBorderStyleChange = form.ClientRectangle;
1175                         form.FormBorderStyle = FormBorderStyle.None;
1176                         Assert.AreEqual (form.Bounds, boundsBeforeBorderStyleChange, "#A1");
1177                         Assert.AreEqual (form.ClientRectangle, clientRectangleBeforeBorderStyleChange, "#A2");
1178
1179                         form.Visible = true;
1180                         form.FormBorderStyle = FormBorderStyle.Sizable;
1181                         boundsBeforeBorderStyleChange = form.Bounds;
1182                         clientRectangleBeforeBorderStyleChange = form.ClientRectangle;
1183                         form.FormBorderStyle = FormBorderStyle.None;
1184                         Assert.IsFalse (form.Bounds == boundsBeforeBorderStyleChange, "#B1");
1185                         Assert.AreEqual (form.ClientRectangle, clientRectangleBeforeBorderStyleChange, "#B2");
1186
1187                         form.Visible = false;
1188                         form.FormBorderStyle = FormBorderStyle.Sizable;
1189                         boundsBeforeBorderStyleChange = form.Bounds;
1190                         clientRectangleBeforeBorderStyleChange = form.ClientRectangle;
1191                         form.FormBorderStyle = FormBorderStyle.None;
1192                         Assert.IsFalse (form.Bounds == boundsBeforeBorderStyleChange, "#C1");
1193                         Assert.AreEqual (form.ClientRectangle, clientRectangleBeforeBorderStyleChange, "#C2");
1194                 }
1195
1196                 [Test]
1197                 [Category ("NotWorking")]
1198                 public void MaximizedParentedFormTest ()
1199                 {
1200                         using (Form Main = new Form ()) {
1201                                 Form Child = new Form ();
1202                                 Child.TopLevel = false;
1203                                 Main.Controls.Add (Child);
1204                                 Main.ShowInTaskbar = false;
1205                                 Main.Show ();
1206                                 
1207                                 Child.WindowState = FormWindowState.Maximized;
1208                                 Child.Visible = true;
1209                                 // The exact negative value depends on the border with, but it should always be < 0.
1210                                 Assert.IsTrue (Child.Location.X < 0 && Child.Location.Y < 0, "#A1");
1211                         }
1212                 }
1213                 [Test]
1214                 [Category ("NotWorking")]
1215                 public void ParentedFormEventTest ()
1216                 {
1217
1218                         using (Form Main = new Form ()) {
1219                                 Form Child = new Form ();
1220                                 Child.TopLevel = false;
1221                                 Child.Visible = true;
1222                                 Main.ShowInTaskbar = false;
1223                                 Main.Show ();
1224
1225                                 EventLogger log = new EventLogger (Child);
1226                                 Assert.AreEqual (true, Child.Visible, "#A0");
1227                                 Main.Controls.Add (Child);
1228                                 Assert.AreEqual (true, Child.Visible, "#B0");
1229                                 Assert.AreEqual ("ParentChanged;BindingContextChanged;Layout;VisibleChanged;BindingContextChanged;BindingContextChanged", log.EventsJoined (), "#B1");
1230                         }
1231                 }
1232                 [Test]
1233                 [NUnit.Framework.Category ("NotWorking")]
1234                 public void FormCreateParamsStyleTest ()
1235                 {
1236                         Form frm;
1237                         
1238                         using (frm = new Form ()) {
1239                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles) TestHelper.GetCreateParams (frm).Style), "#01-Style");
1240                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles) TestHelper.GetCreateParams (frm).ExStyle), "#01-ExStyle");
1241                         }
1242
1243                         using (frm = new Form ()) {
1244                                 frm.AllowDrop = !frm.AllowDrop;
1245                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#02-Style");
1246                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#02-ExStyle");
1247                         }
1248
1249                         using (frm = new Form ()) {
1250                                 frm.AllowTransparency = !frm.AllowTransparency;
1251                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#03-Style");
1252                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_LAYERED, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#03-ExStyle");
1253                         }
1254
1255                         using (frm = new Form ()) {
1256                                 frm.Opacity = 0.50;
1257                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#04-Style");
1258                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_LAYERED, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#04-ExStyle");
1259                         }
1260
1261                         using (frm = new Form ()) {
1262                                 frm.TransparencyKey = Color.Cyan;
1263                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#05-Style");
1264                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_LAYERED, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#05-ExStyle");
1265                         }
1266                         
1267                         using (frm = new Form ()) {
1268                                 frm.CausesValidation = !frm.CausesValidation;
1269                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#06-Style");
1270                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#06-ExStyle");
1271                         }
1272
1273                         using (frm = new Form ()) {
1274                                 frm.ControlBox = !frm.ControlBox;
1275                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_THICKFRAME | WindowStyles.WS_BORDER | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#07-Style");
1276                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#07-ExStyle");
1277                         }
1278
1279                         using (frm = new Form ()) {
1280                                 frm.Enabled = true;
1281                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#08-Style");
1282                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#08-ExStyle");
1283                         }
1284
1285                         using (frm = new Form ()) {
1286                                 frm.FormBorderStyle = FormBorderStyle.Fixed3D;
1287                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#10-Style");
1288                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CLIENTEDGE | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#10-ExStyle");
1289                         }
1290
1291                         using (frm = new Form ()) {
1292                                 frm.FormBorderStyle = FormBorderStyle.FixedDialog;
1293                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#11-Style");
1294                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#11-ExStyle");
1295                         }
1296
1297                         using (frm = new Form ()) {
1298                                 frm.FormBorderStyle = FormBorderStyle.FixedSingle;
1299                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#12-Style");
1300                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#12-ExStyle");
1301                         }
1302
1303                         using (frm = new Form ()) {
1304                                 frm.FormBorderStyle = FormBorderStyle.FixedToolWindow;
1305                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#13-Style");
1306                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_TOOLWINDOW | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#13-ExStyle");
1307                         }
1308
1309                         using (frm = new Form ()) {
1310                                 frm.FormBorderStyle = FormBorderStyle.None;
1311                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#14-Style");
1312                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#14-ExStyle");
1313                         }
1314
1315                         using (frm = new Form ()) {
1316                                 frm.FormBorderStyle = FormBorderStyle.Sizable;
1317                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#15-Style");
1318                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#15-ExStyle");
1319                         }
1320
1321                         using (frm = new Form ()) {
1322                                 frm.FormBorderStyle = FormBorderStyle.SizableToolWindow;
1323                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#16-Style");
1324                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_TOOLWINDOW | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#16-ExStyle");
1325                         }
1326
1327                         using (frm = new Form ()) {
1328                                 frm.HelpButton = !frm.HelpButton;
1329                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#17-Style");
1330                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#17-ExStyle");
1331                         }
1332
1333                         using (frm = new Form ()) {
1334                                 frm.Icon = null;
1335                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#18-Style");
1336                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#18-ExStyle");
1337                         }
1338
1339                         using (frm = new Form ()) {
1340                                 frm.Icon = SystemIcons.Asterisk;
1341                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#19-Style");
1342                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#19-ExStyle");
1343                         }
1344
1345                         using (frm = new Form ()) {
1346                                 frm.IsMdiContainer = !frm.IsMdiContainer;
1347                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#20-Style");
1348                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#20-ExStyle");
1349                         }
1350
1351                         using (frm = new Form ()) {
1352                                 frm.MaximizeBox = !frm.MaximizeBox;
1353                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_GROUP | WindowStyles.WS_THICKFRAME | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#21-Style");
1354                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#21-ExStyle");
1355                         }
1356
1357                         using (frm = new Form ()) {
1358                                 frm.MinimizeBox = !frm.MinimizeBox;
1359                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_THICKFRAME | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#22-Style");
1360                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#22-ExStyle");
1361                         }
1362 #if NET_2_0
1363                         using (frm = new Form ()) {
1364                                 frm.ShowIcon = !frm.ShowIcon;
1365                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#23-Style");
1366                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#23-ExStyle");
1367                         }
1368 #endif          
1369                         using (frm = new Form ()) {
1370                                 frm.ShowInTaskbar = !frm.ShowInTaskbar;
1371                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#24-Style");
1372                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#24-ExStyle");
1373                         }
1374
1375
1376                         using (frm = new Form ()) {
1377                                 frm.TabStop = !frm.TabStop;
1378                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#25-Style");
1379                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#25-ExStyle");
1380                         }
1381
1382                         using (frm = new Form ()) {
1383                                 frm.TopLevel = !frm.TopLevel;
1384                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_CHILD, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#26-Style");
1385                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#26-ExStyle");
1386                         }
1387
1388                         using (frm = new Form ()) {
1389                                 frm.Visible = !frm.Visible;
1390                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#27-Style");
1391                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#27-ExStyle");
1392                         }
1393
1394                         using (frm = new Form ()) {
1395                                 frm.ControlBox = false;
1396                                 frm.Text = "";
1397                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_THICKFRAME | WindowStyles.WS_BORDER | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#28-Style");
1398                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#28-ExStyle");
1399                         }
1400                 }
1401                 
1402                 [Test]
1403                 public void FormParentedTest ()
1404                 {
1405                         using (Form frm = new Form ()) {
1406                                 using (Form frm2 = new Form ()) {
1407                                         frm2.TopLevel = false;
1408                                         frm.ShowInTaskbar = false;
1409                                         frm2.ShowInTaskbar = false;
1410                                         frm2.Visible = true;
1411                                         frm.Visible = true;
1412                                         
1413                                         EventLogger log = new EventLogger (frm);
1414                                         EventLogger log2 = new EventLogger (frm2);
1415                                         
1416                                         frm.Controls.Add (frm2);
1417
1418                                         Assert.IsTrue (log2.EventRaised ("ParentChanged"), "#C1");
1419                                         Assert.IsTrue (log.EventRaised ("ControlAdded"), "#P1");
1420                                         Assert.AreSame (frm, frm2.Parent, "#02");
1421                                 }
1422                         }
1423                 }
1424                 
1425                 [Test]
1426                 public void FormPropertyTest ()
1427                 {
1428                         Form myform = new Form ();
1429                         myform.Visible = true;
1430                         myform.Text = "NewForm";
1431                         myform.Name = "FormTest";
1432                         Assert.IsNull (myform.ActiveMdiChild, "#2"); 
1433                         Assert.IsFalse (myform.AutoScale, "#3");
1434                         Assert.IsNull (myform.CancelButton, "#6");
1435                         Assert.IsTrue (myform.ControlBox, "#9");
1436                         Assert.IsTrue (myform.DesktopBounds.X > 0, "#10a");
1437                         Assert.IsTrue (myform.DesktopBounds.Y > 0, "#10b");
1438                         Assert.AreEqual (300, myform.DesktopBounds.Height, "#10c");
1439                         Assert.AreEqual (300, myform.DesktopBounds.Width, "#10d");
1440                         Assert.IsTrue (myform.DesktopLocation.X > 0, "#11a");
1441                         Assert.IsTrue (myform.DesktopLocation.Y > 0, "#11b");
1442                         Assert.AreEqual (DialogResult.None, myform.DialogResult, "#12");
1443                         Assert.AreEqual (FormBorderStyle.Sizable, myform.FormBorderStyle, "#13");
1444                         Assert.IsFalse (myform.HelpButton, "#14");
1445                         Assert.AreEqual ("System.Drawing.Icon", myform.Icon.GetType ().ToString (), "#15");
1446                         Assert.IsFalse (myform.IsMdiChild, "#16");
1447                         Assert.IsFalse (myform.IsMdiContainer, "#17");
1448                         Assert.IsFalse (myform.KeyPreview, "#18");
1449                         Assert.IsTrue (myform.MaximizeBox, "#19");
1450                         Assert.AreEqual (0, myform.MaximumSize.Height, "#20a");
1451                         Assert.AreEqual (0, myform.MaximumSize.Width, "#20b");
1452                         Assert.AreEqual (0, myform.MdiChildren.Length, "#21a");
1453                         Assert.AreEqual (1, myform.MdiChildren.Rank, "#21b");
1454                         Assert.IsFalse (myform.MdiChildren.IsSynchronized, "#21c");
1455                         Assert.IsNull (myform.MdiParent, "#22");
1456                         Assert.IsNull (myform.Menu, "#23");
1457                         Assert.IsNull (myform.MergedMenu, "#24");
1458                         Assert.IsTrue (myform.MinimizeBox, "#25");
1459                         Assert.AreEqual (0, myform.MinimumSize.Height, "#26a");
1460                         Assert.AreEqual (0, myform.MinimumSize.Width, "#26b");
1461                         Assert.IsTrue (myform.MinimumSize.IsEmpty, "#26c");
1462                         Assert.IsFalse (myform.Modal, "#27");
1463                         Assert.AreEqual (1, myform.Opacity, "#28");
1464                         Assert.AreEqual (0, myform.OwnedForms.Length, "#29a");
1465                         Assert.AreEqual (1, myform.OwnedForms.Rank, "#29b");
1466                         Assert.IsNull (myform.Owner, "#30");
1467                         Assert.IsTrue (myform.ShowInTaskbar, "#31");
1468                         Assert.AreEqual (300, myform.Size.Height, "#32a");
1469                         Assert.AreEqual (300, myform.Size.Width, "#32b");
1470                         Assert.AreEqual (SizeGripStyle.Auto, myform.SizeGripStyle, "#33");
1471                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, myform.StartPosition, "#34");
1472                         Assert.IsTrue (myform.TopLevel, "#35");
1473                         Assert.IsFalse (myform.TopMost, "#36");
1474                         Assert.AreEqual (Color.Empty, myform.TransparencyKey, "#37");
1475                         Assert.AreEqual (FormWindowState.Normal, myform.WindowState, "#38");
1476                         Assert.AreEqual (ImeMode.NoControl, myform.ImeMode, "#39");
1477                         myform.Dispose ();
1478                 }
1479
1480                 [Test]
1481                 [Category ("NotWorking")]
1482                 public void ActivateTest ()
1483                 {
1484                         Form myform = new Form ();
1485                         myform.ShowInTaskbar = false;
1486                         myform.Visible = true;
1487                         myform.Text = "NewForm";
1488                         myform.Name = "FormTest";
1489                         myform.Activate ();
1490                         Assert.AreEqual (true, myform.Focus (), "#40");
1491                         myform.Dispose ();
1492                 }
1493
1494                 [Test]
1495                 public void AddOwnedFormTest ()
1496                 {
1497                         Form parent = new Form ();
1498                         parent.ShowInTaskbar = false;
1499                         parent.Text = "NewParent";
1500                         Form ownedForm = new Form ();
1501                         ownedForm.ShowInTaskbar = false;
1502                         ownedForm.Text = "Owned Form";
1503                         parent.AddOwnedForm (ownedForm);
1504                         ownedForm.Show ();
1505                         Assert.AreEqual ("NewParent", ownedForm.Owner.Text, "#41");
1506                         ownedForm.Dispose ();
1507                         parent.Dispose ();
1508                 }
1509
1510                 [Test] // bug #80020
1511                 public void IsHandleCreated ()
1512                 {
1513                         Form main = new Form ();
1514                         main.Name = "main";
1515                         main.IsMdiContainer = true;
1516                         main.ShowInTaskbar = false;
1517                         Assert.IsFalse (main.IsHandleCreated, "#1");
1518
1519                         Form child = new Form ();
1520                         child.MdiParent = main;
1521                         child.WindowState = FormWindowState.Maximized;
1522                         Assert.IsFalse (main.IsHandleCreated, "#2");
1523
1524                         child.Show ();
1525                         Assert.IsFalse (child.IsHandleCreated, "#3");
1526                         Assert.IsFalse (main.IsHandleCreated, "#4");
1527
1528                         main.Show ();
1529                         Assert.IsTrue (child.IsHandleCreated, "#5");
1530                         Assert.IsTrue (main.IsHandleCreated, "#6");
1531
1532                         child.Dispose ();
1533                         main.Dispose ();
1534                 }
1535
1536                 [Test]
1537                 public void RemoveOwnedFormTest ()
1538                 {
1539                         Form myform = new Form ();
1540                         myform.ShowInTaskbar = false;
1541                         myform.Text = "NewForm";
1542                         myform.Name = "FormTest";
1543                         myform.RemoveOwnedForm (myform);
1544                         myform.Show ();
1545                         Assert.AreEqual (null, myform.Owner, "#44");
1546                         myform.Dispose ();
1547                 }
1548
1549                 [Test]
1550                 public void SetDesktopBoundsTest ()
1551                 {
1552                         Form myform = new Form ();
1553                         myform.ShowInTaskbar = false;
1554                         myform.Visible = true;
1555                         myform.Text = "NewForm";
1556                         myform.Name = "FormTest";
1557                         myform.SetDesktopBounds (10, 10, 200 , 200);
1558                         Assert.AreEqual (200, myform.DesktopBounds.Height, "#45");
1559                         myform.Dispose ();
1560                 }
1561
1562                 [Test]
1563                 public void SetDesktopLocationTest ()
1564                 {
1565                         Form myform = new Form ();
1566                         myform.ShowInTaskbar = false;
1567                         myform.Visible = true;
1568                         myform.Text = "NewForm";
1569                         myform.Name = "FormTest";
1570                         myform.SetDesktopLocation (10, 10);
1571                         Assert.AreEqual (10, myform.DesktopLocation.X, "#46");
1572                         myform.Dispose ();
1573                 }
1574
1575                 [Test]
1576                 public void SetDialogResultOutOfRange ()
1577                 {
1578                         Form myform = new Form ();
1579                         myform.ShowInTaskbar = false;
1580                         try {
1581                                 myform.DialogResult = (DialogResult) (-1);
1582                                 Assert.Fail ("#48");
1583                         } catch (InvalidEnumArgumentException) {
1584                         }
1585
1586                         try {
1587                                 myform.DialogResult = (DialogResult) ((int) DialogResult.No + 1);
1588                                 Assert.Fail ("#49");
1589                         } catch (InvalidEnumArgumentException) {
1590                         }
1591                         myform.Dispose ();
1592                 }
1593
1594                 void myform_set_dialogresult (object sender, EventArgs e)
1595                 {
1596                         Form f = (Form)sender;
1597
1598                         f.DialogResult = DialogResult.OK;
1599                 }
1600
1601                 void myform_close (object sender, EventArgs e)
1602                 {
1603                         Form f = (Form)sender;
1604
1605                         f.Close();
1606                 }
1607
1608                 [Test]
1609                 public void SetDialogResult ()
1610                 {
1611                         Form myform = new Form ();
1612                         myform.ShowInTaskbar = false;
1613                         myform.Visible = true;
1614
1615                         myform.DialogResult = DialogResult.Cancel;
1616
1617                         Assert.IsTrue (myform.Visible, "A1");
1618                         Assert.IsFalse (myform.IsDisposed, "A2");
1619
1620                         myform.Close ();
1621
1622                         Assert.IsFalse (myform.Visible, "A3");
1623                         Assert.IsTrue (myform.IsDisposed, "A4");
1624
1625                         DialogResult result;
1626
1627                         myform = new Form ();
1628                         myform.ShowInTaskbar = false;
1629                         myform.VisibleChanged += new EventHandler (myform_set_dialogresult);
1630                         result = myform.ShowDialog ();
1631
1632                         Assert.AreEqual (result, DialogResult.OK, "A5");
1633                         Assert.IsFalse (myform.Visible, "A6");
1634                         Assert.IsFalse (myform.IsDisposed, "A7");
1635                         myform.Dispose ();
1636                         
1637                         myform = new Form ();
1638                         myform.ShowInTaskbar = false;
1639                         myform.VisibleChanged += new EventHandler (myform_close);
1640                         result = myform.ShowDialog ();
1641
1642                         Assert.AreEqual (result, DialogResult.Cancel, "A8");
1643                         Assert.IsFalse (myform.Visible, "A9");
1644                         Assert.IsFalse (myform.IsDisposed, "A10");
1645                         
1646                         myform.Dispose ();
1647                 }
1648
1649                 [Test]
1650                 public void ShowDialog_Child ()
1651                 {
1652                         Form main = new Form ();
1653                         main.IsMdiContainer = true;
1654                         Form child = new Form ();
1655                         child.MdiParent = main;
1656                         try {
1657                                 child.ShowDialog ();
1658                                 Assert.Fail ("#1");
1659                         } catch (InvalidOperationException ex) {
1660                                 // Forms that are not top level forms cannot be displayed as a
1661                                 // modal dialog. Remove the form from any parent form before 
1662                                 // calling ShowDialog.
1663                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1664                                 Assert.IsNull (ex.InnerException, "#3");
1665                                 Assert.IsNotNull (ex.Message, "#4");
1666                         }
1667                         Assert.IsNull (child.Owner, "#5");
1668                         child.Dispose ();
1669                         main.Dispose ();
1670                 }
1671
1672                 [Test]
1673                 public void ShowDialog_Disabled ()
1674                 {
1675                         Form form = new Form ();
1676                         form.Enabled = false;
1677                         try {
1678                                 form.ShowDialog ();
1679                                 Assert.Fail ("#A1");
1680                         } catch (InvalidOperationException ex) {
1681                                 // Forms that are not enabled cannot be displayed as a modal
1682                                 // dialog. Set the form's enabled property to true before
1683                                 // calling ShowDialog.
1684                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1685                                 Assert.IsNull (ex.InnerException, "#A3");
1686                                 Assert.IsNotNull (ex.Message, "#A4");
1687                         }
1688                         Assert.IsNull (form.Owner, "#A5");
1689                         form.Dispose ();
1690
1691                         Form main = new Form ();
1692                         form = new Form ();
1693                         form.Owner = main;
1694                         form.Enabled = false;
1695                         try {
1696                                 form.ShowDialog ();
1697                                 Assert.Fail ("#B1");
1698                         } catch (InvalidOperationException) {
1699                         }
1700                         Assert.IsNotNull (form.Owner, "#B2");
1701                         Assert.AreSame (main, form.Owner, "#B3");
1702                         form.Dispose ();
1703                         main.Dispose ();
1704                 }
1705
1706                 [Test]
1707                 [Category ("NotWorking")]
1708                 public void ShowDialog_Owner_Circular ()
1709                 {
1710                         Form main = new Form ();
1711                         Form child = new Form ();
1712                         child.Owner = main;
1713                         try {
1714                                 main.ShowDialog (child);
1715                                 Assert.Fail ("#1");
1716                         } catch (ArgumentException ex) {
1717                                 // A circular control reference has been made. A control cannot
1718                                 // be owned or parented to itself
1719                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1720                                 Assert.IsNull (ex.InnerException, "#3");
1721                                 Assert.IsNotNull (ex.Message, "#4");
1722                                 Assert.IsNull (ex.ParamName, "#5");
1723                         }
1724                         Assert.IsNull (main.Owner, "#6");
1725                         main.Dispose ();
1726                         child.Dispose ();
1727                 }
1728
1729                 [Test] // bug #80773
1730                 public void ShowDialog_Owner_Self ()
1731                 {
1732                         Form form = new Form ();
1733                         try {
1734                                 form.ShowDialog (form);
1735                                 Assert.Fail ("#A1");
1736                         } catch (ArgumentException ex) {
1737                                 // Forms cannot own themselves or their owners
1738                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1739                                 Assert.IsNull (ex.InnerException, "#A3");
1740                                 Assert.IsNotNull (ex.Message, "#A4");
1741                                 Assert.IsNotNull (ex.ParamName, "#A5");
1742                                 Assert.AreEqual ("owner", ex.ParamName, "#A6");
1743                         }
1744                         Assert.IsNull (form.Owner, "#A7");
1745                         form.Dispose ();
1746
1747                         Form main = new Form ();
1748                         form = new Form ();
1749                         form.Owner = main;
1750                         try {
1751                                 form.ShowDialog (form);
1752                                 Assert.Fail ("#B1");
1753                         } catch (ArgumentException) {
1754                         }
1755                         Assert.IsNotNull (form.Owner);
1756                         Assert.AreSame (main, form.Owner, "#B2");
1757                         form.Dispose ();
1758                         main.Dispose ();
1759                 }
1760
1761                 [Test]
1762                 public void ShowDialog_Visible ()
1763                 {
1764                         Form form = new Form ();
1765                         form.ShowInTaskbar = false;
1766                         form.Visible = true;
1767                         try {
1768                                 form.ShowDialog ();
1769                                 Assert.Fail ("#A1");
1770                         } catch (InvalidOperationException ex) {
1771                                 // Forms that are already visible cannot be displayed as a modal
1772                                 // dialog. Set the form's visible property to false before 
1773                                 // calling ShowDialog.
1774                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1775                                 Assert.IsNull (ex.InnerException, "#A3");
1776                                 Assert.IsNotNull (ex.Message, "#A4");
1777                         }
1778                         Assert.IsNull (form.Owner, "#A5");
1779                         form.Dispose ();
1780
1781                         Form main = new Form ();
1782                         form = new Form ();
1783                         form.Owner = main;
1784                         form.Visible = true;
1785                         try {
1786                                 form.ShowDialog ();
1787                                 Assert.Fail ("#B1");
1788                         } catch (InvalidOperationException) {
1789                         }
1790                         Assert.IsNotNull (form.Owner, "#B2");
1791                         Assert.AreSame (main, form.Owner, "#B3");
1792                         form.Dispose ();
1793                         main.Dispose ();
1794                 }
1795
1796                 [Test] // bug #80604
1797                 public void VisibleOnLoad ()
1798                 {
1799                         MockForm form = new MockForm ();
1800                         form.CloseOnLoad = true;
1801                         Application.Run (form);
1802                         Assert.IsTrue (form.VisibleOnLoad, "#1");
1803                         form.Dispose ();
1804
1805                         form = new MockForm ();
1806                         form.ShowInTaskbar = false;
1807                         form.Show ();
1808                         Assert.IsTrue (form.VisibleOnLoad, "#2");
1809                         form.Dispose ();
1810                 }
1811
1812                 [Test] // bug #80052
1813                 [Category ("NotWorking")]
1814                 public void Location ()
1815                 {
1816                         // 
1817                         // CenterParent
1818                         // 
1819
1820                         Form formA = new Form ();
1821                         formA.ShowInTaskbar = false;
1822                         formA.StartPosition = FormStartPosition.CenterParent;
1823                         formA.Location = new Point (151, 251);
1824                         formA.Show ();
1825
1826                         Assert.AreEqual (FormStartPosition.CenterParent, formA.StartPosition, "#A1");
1827                         Assert.IsFalse (formA.Location.X == 151, "#A2");
1828                         Assert.IsFalse (formA.Location.Y == 251, "#A3");
1829
1830                         formA.Location = new Point (311, 221);
1831
1832                         Assert.AreEqual (FormStartPosition.CenterParent, formA.StartPosition, "#A4");
1833                         Assert.AreEqual (311, formA.Location.X, "#A5");
1834                         Assert.AreEqual (221, formA.Location.Y, "#A6");
1835
1836                         formA.Dispose ();
1837
1838                         // 
1839                         // CenterScreen
1840                         // 
1841
1842                         Form formB = new Form ();
1843                         formB.ShowInTaskbar = false;
1844                         formB.StartPosition = FormStartPosition.CenterScreen;
1845                         formB.Location = new Point (151, 251);
1846                         formB.Show ();
1847
1848                         Assert.AreEqual (FormStartPosition.CenterScreen, formB.StartPosition, "#B1");
1849                         Assert.IsFalse (formB.Location.X == 151, "#B2");
1850                         Assert.IsFalse (formB.Location.Y == 251, "#B3");
1851
1852                         formB.Location = new Point (311, 221);
1853
1854                         Assert.AreEqual (FormStartPosition.CenterScreen, formB.StartPosition, "#B4");
1855                         Assert.AreEqual (311, formB.Location.X, "#B5");
1856                         Assert.AreEqual (221, formB.Location.Y, "#B6");
1857
1858                         formB.Dispose ();
1859
1860                         // 
1861                         // Manual
1862                         // 
1863
1864                         Form formC = new Form ();
1865                         formC.ShowInTaskbar = false;
1866                         formC.StartPosition = FormStartPosition.Manual;
1867                         formC.Location = new Point (151, 251);
1868                         formC.Show ();
1869
1870                         Assert.AreEqual (FormStartPosition.Manual, formC.StartPosition, "#C1");
1871                         Assert.AreEqual (151, formC.Location.X, "#C2");
1872                         Assert.AreEqual (251, formC.Location.Y, "#C3");
1873
1874                         formC.Location = new Point (311, 221);
1875
1876                         Assert.AreEqual (FormStartPosition.Manual, formC.StartPosition, "#C4");
1877                         Assert.AreEqual (311, formC.Location.X, "#C5");
1878                         Assert.AreEqual (221, formC.Location.Y, "#C6");
1879
1880                         formC.Dispose ();
1881
1882                         // 
1883                         // WindowsDefaultBounds
1884                         // 
1885
1886                         Form formD = new Form ();
1887                         formD.ShowInTaskbar = false;
1888                         formD.StartPosition = FormStartPosition.WindowsDefaultBounds;
1889                         formD.Location = new Point (151, 251);
1890                         formD.Show ();
1891
1892                         Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, formD.StartPosition, "#D1");
1893                         Assert.IsFalse (formD.Location.X == 151, "#D2");
1894                         Assert.IsFalse (formD.Location.Y == 251, "#D3");
1895
1896                         formD.Location = new Point (311, 221);
1897
1898                         Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, formD.StartPosition, "#D4");
1899                         Assert.AreEqual (311, formD.Location.X, "#D5");
1900                         Assert.AreEqual (221, formD.Location.Y, "#D6");
1901
1902                         formD.Dispose ();
1903
1904                         // 
1905                         // WindowsDefaultLocation
1906                         // 
1907
1908                         Form formE = new Form ();
1909                         formE.ShowInTaskbar = false;
1910                         formE.Location = new Point (151, 251);
1911                         formE.Show ();
1912
1913                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, formE.StartPosition, "#E1");
1914                         Assert.IsFalse (formE.Location.X == 151, "#E2");
1915                         Assert.IsFalse (formE.Location.Y == 251, "#E3");
1916
1917                         formE.Location = new Point (311, 221);
1918
1919                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, formE.StartPosition, "#E4");
1920                         Assert.AreEqual (311, formE.Location.X, "#E5");
1921                         Assert.AreEqual (221, formE.Location.Y, "#E6");
1922
1923                         formE.Dispose ();
1924                 }
1925
1926                 [Test]
1927                 public void Opacity ()
1928                 {
1929                         Form frm;
1930                         using (frm = new Form ()) {
1931                                 Assert.AreEqual (1.0f, frm.Opacity, "#01-opacity");
1932                                 frm.Opacity = 0.50;
1933                                 Assert.AreEqual (0.50f, frm.Opacity, "#02-opacity");
1934                                 frm.Opacity = -0.1f;
1935                                 Assert.AreEqual (0, frm.Opacity, "#03-opacity");
1936                                 frm.Opacity = 1.1f;
1937                                 Assert.AreEqual (1, frm.Opacity, "#04-opacity");
1938                         }
1939                 }
1940
1941                 [Test]
1942                 public void DisposeOwnerTest ()
1943                 {
1944                         Form f1 = new Form ();
1945                         Form f2 = new Form ();
1946
1947                         f2.Owner = f1;
1948
1949                         f1.Dispose ();
1950
1951                         Assert.IsNull (f2.Owner, "1");
1952                         Assert.AreEqual (0, f1.OwnedForms.Length, "2");
1953                 }
1954
1955                 [Test]
1956                 [ExpectedException (typeof (ObjectDisposedException))]
1957                 public void AccessDisposedForm ()
1958                 {
1959                         Form myform = new Form ();
1960                         myform.ShowInTaskbar = false;
1961
1962                         myform.Show ();
1963                         myform.Close (); // this should result in the form being disposed
1964                         myform.Show (); // and this line should result in the ODE being thrown
1965                 }
1966
1967                 class MyForm : Form
1968                 {
1969                         public void DoDestroyHandle ()
1970                         {
1971                                 DestroyHandle();
1972                         }
1973                         public void DoRecreateHandle ()
1974                         {
1975                                 RecreateHandle();
1976                         }
1977                 }
1978
1979                 int handle_destroyed_count;
1980                 void handle_destroyed (object sender, EventArgs e)
1981                 {
1982                         handle_destroyed_count++;
1983                 }
1984
1985                 [Test]
1986                 public void DestroyHandleTest ()
1987                 {
1988                         handle_destroyed_count = 0;
1989
1990                         MyForm f1 = new MyForm ();
1991                         f1.HandleDestroyed += new EventHandler (handle_destroyed);
1992                         f1.Show ();
1993                         f1.DoDestroyHandle ();
1994                         Assert.AreEqual (1, handle_destroyed_count, "1");
1995
1996                         MyForm f2 = new MyForm ();
1997                         f2.HandleDestroyed += new EventHandler (handle_destroyed);
1998                         f2.Show ();
1999                         f2.DoRecreateHandle ();
2000                         Assert.AreEqual (2, handle_destroyed_count, "2");
2001                         
2002                         f1.Dispose ();
2003                         f2.Dispose ();
2004                 }
2005
2006                 [Test]
2007                 public void FormClose ()
2008                 {
2009                         Form myform = new Form ();
2010                         myform.ShowInTaskbar = false;
2011
2012                         Assert.IsFalse (myform.Visible, "A1");
2013                         Assert.IsFalse (myform.IsDisposed, "A2");
2014
2015                         myform.Close ();
2016 #if NET_2_0
2017                         Assert.IsTrue (myform.IsDisposed, "A3");
2018 #else
2019                         Assert.IsFalse (myform.Visible, "A4");
2020                         Assert.IsFalse (myform.IsDisposed, "A5");
2021
2022                         myform.Show ();
2023
2024                         Assert.IsTrue (myform.Visible, "A6");
2025                         Assert.IsFalse (myform.IsDisposed, "A7");
2026
2027                         myform.Close ();
2028
2029                         Assert.IsFalse (myform.Visible, "A8");
2030                         Assert.IsTrue (myform.IsDisposed, "A9");
2031 #endif
2032                 }
2033
2034                 [Test]
2035                 public void FormClose2 ()
2036                 {
2037                         WMCloseWatcher f = new WMCloseWatcher ();
2038                         f.ShowInTaskbar = false;
2039
2040                         f.close_count = 0;
2041                         Assert.IsFalse (f.Visible, "A1");
2042                         f.Close ();
2043                         Assert.AreEqual (0, f.close_count, "A2");
2044 #if NET_2_0
2045                         Assert.IsTrue (f.IsDisposed, "A3");
2046 #else
2047                         f.Show ();
2048                         f.Close ();
2049                         Assert.AreEqual (1, f.close_count, "A4");
2050 #endif
2051                 }
2052
2053                 class WMCloseWatcher : Form {
2054                         public int close_count;
2055
2056                         protected override void WndProc (ref Message msg) {
2057                                 if (msg.Msg == 0x0010 /* WM_CLOSE */) {
2058                                         close_count ++;
2059                                 }
2060
2061                                 base.WndProc (ref msg);
2062                         }
2063                 }
2064
2065                 class SwallowOnActivated : Form {
2066                         protected override void OnActivated (EventArgs e)
2067                         {
2068                                 // do nothing
2069                         }
2070
2071                         protected override void OnCreateControl () {
2072                                 base.OnCreateControl ();
2073                         }
2074                 }
2075
2076                 class EnterTest : Button {
2077                         protected override void OnEnter (EventArgs e)
2078                         {
2079                                 on_enter = true;
2080                                 base.OnEnter (e);
2081                         }
2082
2083                         public bool on_enter;
2084                 }
2085
2086                 [Test]
2087                 public void OnActivateEventHandlingTest1 ()
2088                 {
2089 //                      if (TestHelper.RunningOnUnix) {
2090 //                              Assert.Ignore ("Relies on form.Show() synchronously generating WM_ACTIVATE");
2091 //                      }
2092
2093                         SwallowOnActivated f = new SwallowOnActivated ();
2094
2095                         f.ShowInTaskbar = false;
2096
2097                         EnterTest c = new EnterTest ();
2098                         f.Controls.Add (c);
2099
2100                         f.Show ();
2101
2102                         Assert.IsTrue (c.on_enter, "1");
2103
2104                         f.Dispose ();
2105                 }
2106                 
2107 #if NET_2_0
2108                 [Test]
2109                 public void FormClosingEvents ()
2110                 {
2111                         // Standard Close
2112                         Form f = new Form ();
2113                         string events = string.Empty;
2114
2115                         f.Closing += new CancelEventHandler (delegate (Object obj, CancelEventArgs e) { events += ("Closing;"); });
2116                         f.FormClosing += new FormClosingEventHandler (delegate (Object obj, FormClosingEventArgs e) { events += string.Format ("FormClosing [Reason:{0} - Cancel:{1}]", e.CloseReason, e.Cancel); });
2117         
2118                         f.Show ();
2119                         f.Close ();
2120                         
2121                         Assert.AreEqual ("Closing;FormClosing [Reason:UserClosing - Cancel:False]", events, "A1");                      
2122                 }
2123
2124                 [Test]
2125                 public void FormClosingEventsCancel ()
2126                 {
2127                         // Shows that setting Cancel in Closing flows through to FormClosing
2128                         Form f = new Form ();
2129                         string events = string.Empty;
2130
2131                         f.Closing += new CancelEventHandler (delegate (Object obj, CancelEventArgs e) { events += ("Closing;"); e.Cancel = true; });
2132                         f.FormClosing += new FormClosingEventHandler (delegate (Object obj, FormClosingEventArgs e) { events += string.Format("FormClosing [Reason:{0} - Cancel:{1}]", e.CloseReason, e.Cancel); e.Cancel = false; });
2133
2134                         f.Show ();
2135                         f.Close ();
2136
2137                         Assert.AreEqual ("Closing;FormClosing [Reason:UserClosing - Cancel:True]", events, "A1");
2138                 }
2139
2140                 [Test]
2141                 public void FormClosedEvents ()
2142                 {
2143                         // Standard Closed
2144                         Form f = new Form ();
2145                         string events = string.Empty;
2146
2147                         f.Closed += new EventHandler (delegate (Object obj, EventArgs e) { events += ("Closed;"); });
2148                         f.FormClosed += new FormClosedEventHandler (delegate (Object obj, FormClosedEventArgs e) { events += string.Format ("FormClosed [Reason:{0}]", e.CloseReason); });
2149
2150                         f.Show ();
2151                         f.Close ();
2152
2153                         Assert.AreEqual ("Closed;FormClosed [Reason:UserClosing]", events, "A1");
2154                 }
2155
2156                 [Test]
2157                 public void ShowWithOwner ()
2158                 {
2159                         Form f = new Form ();
2160                         Button b = new Button ();
2161                         f.Controls.Add (b);
2162
2163                         Form f2 = new Form ();
2164
2165                         f2.Show (f);
2166
2167                         Assert.AreSame (f, f2.Owner, "A1");
2168                         f2.Close ();
2169
2170                         f2 = new Form ();
2171
2172                         f2.Show (b);
2173                         Assert.AreSame (f, f2.Owner, "A2");
2174                         f2.Close ();
2175                         
2176                         Button b2 = new Button ();
2177                         f2 = new Form ();
2178
2179                         f2.Show (b2);
2180                         Assert.AreEqual (null, f2.Owner, "A3");
2181                         f2.Close ();
2182
2183                         f2 = new Form ();
2184                         f2.Show (null);
2185                         Assert.AreEqual (null, f2.Owner, "A4");
2186                         f2.Close ();
2187                         
2188                         f.Dispose ();
2189                 }
2190
2191                 [Test]
2192                 [ExpectedException (typeof (InvalidOperationException))]
2193                 public void ShowWithOwnerIOE ()
2194                 {
2195                         using (Form f = new Form ()) {
2196                                 f.Show (f);
2197                         }
2198                 }
2199                 
2200                 [Test]  // Bug #79959, #80574, #80791
2201                 [Category ("NotWorking")]
2202                 public void BehaviorResizeOnBorderStyleChanged ()
2203                 {
2204                         // Marked NotWorking because the ClientSize is dependent on the WM.
2205                         // The values below match XP Luna to make sure our behavior is the same.
2206                         Form f = new Form ();
2207                         f.ShowInTaskbar = false;
2208                         f.Show ();
2209
2210                         Assert.AreEqual (true, f.IsHandleCreated, "A0");
2211
2212                         Assert.AreEqual (new Size (300, 300), f.Size, "A1");
2213                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A2");
2214
2215                         f.FormBorderStyle = FormBorderStyle.Fixed3D;
2216                         Assert.AreEqual (new Size (302, 302), f.Size, "A3");
2217                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4");
2218
2219                         f.FormBorderStyle = FormBorderStyle.FixedDialog;
2220                         Assert.AreEqual (new Size (298, 298), f.Size, "A5");
2221                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A6");
2222
2223                         f.FormBorderStyle = FormBorderStyle.FixedSingle;
2224                         Assert.AreEqual (new Size (298, 298), f.Size, "A7");
2225                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A8");
2226
2227                         f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
2228                         Assert.AreEqual (new Size (298, 290), f.Size, "A9");
2229                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A0");
2230
2231                         f.FormBorderStyle = FormBorderStyle.None;
2232                         Assert.AreEqual (new Size (292, 266), f.Size, "A11");
2233                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A12");
2234
2235                         f.FormBorderStyle = FormBorderStyle.SizableToolWindow;
2236                         Assert.AreEqual (new Size (300, 292), f.Size, "A13");
2237                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A14");
2238
2239                         f.FormBorderStyle = FormBorderStyle.Sizable;
2240                         Assert.AreEqual (new Size (300, 300), f.Size, "A15");
2241                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A16");
2242                         
2243                         f.Close ();
2244                 }
2245
2246                 [Test]  // Bug #80574, #80791
2247                 [Category ("NotWorking")]
2248                 public void BehaviorResizeOnBorderStyleChangedNotVisible ()
2249                 {
2250                         // Marked NotWorking because the ClientSize is dependent on the WM.
2251                         // The values below match XP Luna to make sure our behavior is the same.
2252                         Form f = new Form ();
2253                         f.ShowInTaskbar = false;
2254
2255                         Assert.AreEqual (false, f.IsHandleCreated, "A0");
2256                         
2257                         Assert.AreEqual (new Size (300, 300), f.Size, "A1");
2258                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A2");
2259
2260                         f.FormBorderStyle = FormBorderStyle.Fixed3D;
2261                         Assert.AreEqual (new Size (300, 300), f.Size, "A3");
2262                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4");
2263
2264                         f.FormBorderStyle = FormBorderStyle.FixedDialog;
2265                         Assert.AreEqual (new Size (300, 300), f.Size, "A5");
2266                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A6");
2267
2268                         f.FormBorderStyle = FormBorderStyle.FixedSingle;
2269                         Assert.AreEqual (new Size (300, 300), f.Size, "A7");
2270                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A8");
2271
2272                         f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
2273                         Assert.AreEqual (new Size (300, 300), f.Size, "A9");
2274                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A0");
2275
2276                         f.FormBorderStyle = FormBorderStyle.None;
2277                         Assert.AreEqual (new Size (300, 300), f.Size, "A11");
2278                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A12");
2279
2280                         f.FormBorderStyle = FormBorderStyle.SizableToolWindow;
2281                         Assert.AreEqual (new Size (300, 300), f.Size, "A13");
2282                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A14");
2283
2284                         f.FormBorderStyle = FormBorderStyle.Sizable;
2285                         Assert.AreEqual (new Size (300, 300), f.Size, "A15");
2286                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A16");
2287                 }
2288
2289                 [Test]  // Bug #80574, #80791
2290                 [Category ("NotWorking")]
2291                 public void MoreBehaviorResizeOnBorderStyleChangedNotVisible ()
2292                 {
2293                         // Marked NotWorking because the ClientSize is dependent on the WM.
2294                         // The values below match XP Luna to make sure our behavior is the same.
2295                         Form f = new Form ();
2296                         f.ShowInTaskbar = false;
2297
2298                         f.Show ();
2299                         f.Hide ();
2300
2301                         Assert.AreEqual (true, f.IsHandleCreated, "A0");
2302
2303                         f.FormBorderStyle = FormBorderStyle.Sizable;
2304                         Assert.AreEqual (new Size (300, 300), f.Size, "A1");
2305                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A2");
2306                         f.FormBorderStyle = FormBorderStyle.None;
2307                         Assert.AreEqual (new Size (292, 266), f.Size, "A3");
2308                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4");
2309                 }
2310 #endif
2311
2312                 [Test]  // bug #438866
2313                 public void MinMaxSize ()
2314                 {
2315                         Form f = new Form ();
2316                         
2317                         f.MinimumSize = new Size (200, 200);
2318                         f.MaximumSize = new Size (150, 150);
2319
2320                         Assert.AreEqual (new Size (150, 150), f.MinimumSize, "A1");
2321                         Assert.AreEqual (new Size (150, 150), f.MaximumSize, "A2");
2322                         
2323                         f.MinimumSize = new Size (200, 200);
2324
2325                         Assert.AreEqual (new Size (200, 200), f.MinimumSize, "A3");
2326                         Assert.AreEqual (new Size (200, 200), f.MaximumSize, "A4");
2327                         
2328                         f.Dispose ();
2329                 }
2330
2331                 [Test]
2332                 public void MinSizeIssue ()
2333                 {
2334                         Form f = new Form ();
2335
2336                         f.MinimumSize = new Size (100, 100);
2337
2338                         f.Show ();
2339
2340                         Assert.AreEqual (new Size (300, 300), f.Size, "A1");
2341
2342                         f.Dispose ();
2343                 }
2344                 
2345                 [Test]  // Bug #81582
2346                 [Category ("NotWorking")]
2347                 public void GotFocusWithoutCallingOnLoadBase ()
2348                 {
2349                         NoOnLoadBaseForm f = new NoOnLoadBaseForm ();
2350                         f.Show ();
2351                         Assert.AreEqual (true, f.got_focus_called, "H1");
2352                         f.Dispose ();
2353                 }
2354
2355                 private class NoOnLoadBaseForm : Form
2356                 {
2357                         public bool got_focus_called = false;
2358
2359                         public NoOnLoadBaseForm ()
2360                         {
2361                                 TreeView tv = new TreeView ();
2362                                 tv.GotFocus += new EventHandler (tv_GotFocus);
2363                                 Controls.Add (tv);
2364                         }
2365
2366                         void tv_GotFocus (object sender, EventArgs e)
2367                         {
2368                                 got_focus_called = true;
2369                         }
2370
2371                         protected override void OnLoad (EventArgs e)
2372                         {
2373                         }
2374                 }
2375
2376                 [Test] // bug #339641
2377                 public void ChildFocused ()
2378                 {
2379 //                      if (TestHelper.RunningOnUnix) {
2380 //                              Assert.Ignore ("Relies on form.Show() synchronously generating WM_ACTIVATE");
2381 //                      }
2382                         using (Form f = new TimeBombedForm ()) {
2383                                 TreeView tv = new TreeView ();
2384                                 EventLogger log = new EventLogger (tv);
2385                                 tv.GotFocus += new EventHandler (tv_GotFocus);
2386                                 f.Activated += new EventHandler (f_Activated);
2387                                 f.Controls.Add (tv);
2388                                 f.Show ();
2389                                 Assert.IsTrue (log.EventRaised ("GotFocus"), "#01");
2390                         }
2391                 }
2392
2393                 void f_Activated (object sender, EventArgs e)
2394                 {
2395                         //Console.WriteLine ("         ACTIVATED");
2396                         //Console.WriteLine (Environment.StackTrace);
2397                 }
2398
2399                 void tv_GotFocus (object sender, EventArgs e)
2400                 {
2401                         //Console.WriteLine (Environment.StackTrace);
2402                 }
2403
2404                 [Test]  // bug #80773
2405                 public void DontSetOwnerOnShowDialogException ()
2406                 {
2407                         Form f = new Form ();
2408                         f.ShowInTaskbar = false;
2409                         
2410                         try { f.ShowDialog (f); }
2411                         catch { }
2412                         
2413                         Assert.AreEqual (null, f.Owner, "H1");
2414
2415                         f.Dispose ();
2416                 }
2417
2418                 [Test]
2419                 public void MinimumWindowSize ()
2420                 {
2421                         Form f = new Form ();
2422                         f.ShowInTaskbar = false;
2423                         f.Show ();
2424                         
2425                         f.Size = new Size (0, 0);
2426                         Assert.AreEqual (SystemInformation.MinimumWindowSize, f.Size);
2427
2428                         f.Dispose ();
2429                 }
2430
2431                 [Test]
2432                 public void Bug82470 ()
2433                 {
2434                         Form f = new Form ();
2435                         f.Load += new EventHandler (Form_LoadAndHide);
2436                         f.Show ();
2437                         
2438                         Assert.AreEqual (true, f.Visible, "A1");
2439                         
2440                         f.Dispose ();
2441                 }
2442
2443                 private void Form_LoadAndHide (object sender, EventArgs e)
2444                 {
2445                         ((Form)sender).Visible = false;
2446                 }
2447                 
2448 #if NET_2_0
2449                 [Test]
2450                 public void AutoSizeGrowOnly ()
2451                 {
2452                         Form f = new Form ();
2453                         f.ShowInTaskbar = false;
2454                         f.AutoSize = true;
2455
2456                         Button b = new Button ();
2457                         b.Size = new Size (200, 200);
2458                         b.Location = new Point (200, 200);
2459                         f.Controls.Add (b);
2460
2461                         f.Show ();
2462
2463                         Assert.AreEqual (new Size (403, 403), f.ClientSize, "A1");
2464                         
2465                         f.Controls.Remove (b);
2466                         Assert.AreEqual (new Size (403, 403), f.ClientSize, "A2");
2467                 
2468                         f.Dispose ();
2469                 }
2470
2471                 [Test]
2472                 public void AutoSizeReset ()
2473                 {
2474                         Form f = new Form ();
2475                         f.ShowInTaskbar = false;
2476
2477                         Button b = new Button ();
2478                         b.Size = new Size (200, 200);
2479                         b.Location = new Point (200, 200);
2480                         f.Controls.Add (b);
2481
2482                         f.Show ();
2483
2484                         Size start_size = f.ClientSize;
2485
2486                         f.AutoSize = true;
2487                         Assert.AreEqual (new Size (403, 403), f.ClientSize, "A1");
2488
2489                         f.AutoSize = false;
2490                         Assert.AreEqual (start_size, f.ClientSize, "A2");
2491                         f.Close ();
2492                 }
2493
2494                 [Test]
2495                 public void AutoSizeGrowAndShrink ()
2496                 {
2497                         Form f = new Form ();
2498                         f.ShowInTaskbar = false;
2499                         f.AutoSize = true;
2500                         f.AutoSizeMode = AutoSizeMode.GrowAndShrink;
2501
2502                         f.Show ();
2503
2504                         // Make sure form shrunk
2505                         Assert.IsTrue (f.ClientSize.Width < 150, "A1");
2506                         Assert.IsTrue (f.ClientSize.Height < 150, "A1-2");
2507
2508                         Button b = new Button ();
2509                         b.Size = new Size (200, 200);
2510                         b.Location = new Point (0, 0);
2511                         f.Controls.Add (b);
2512
2513                         Assert.AreEqual (new Size (203, 203), f.ClientSize, "A2");
2514                         f.Dispose ();
2515                 }
2516
2517                 [Test]
2518                 public void GetScaledBoundsTest ()
2519                 {
2520                         if (TestHelper.RunningOnUnix)
2521                                 Assert.Ignore ("Depends on WM decoration sizes, values correspond to windows");
2522
2523                         ScaleForm c = new ScaleForm ();
2524
2525                         Rectangle r = new Rectangle (100, 200, 300, 400);
2526
2527                         Assert.AreEqual (new Rectangle (100, 200, 584, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A1");
2528                         Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A2");
2529                         Assert.AreEqual (new Rectangle (100, 200, 584, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A3");
2530                         Assert.AreEqual (new Rectangle (100, 200, 300, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A4");
2531                         Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A5");
2532                         Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A6");
2533
2534                         Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (1f, 1f), BoundsSpecified.All), "A6-2");
2535                         Assert.AreEqual (new Rectangle (100, 200, 584, 764), c.PublicGetScaledBounds (r, new SizeF (2f, 2f), BoundsSpecified.All), "A7");
2536                         Assert.AreEqual (new Rectangle (100, 200, 868, 1128), c.PublicGetScaledBounds (r, new SizeF (3f, 3f), BoundsSpecified.All), "A8");
2537                         Assert.AreEqual (new Rectangle (100, 200, 1152, 1492), c.PublicGetScaledBounds (r, new SizeF (4f, 4f), BoundsSpecified.All), "A9");
2538                         Assert.AreEqual (new Rectangle (100, 200, 158, 218), c.PublicGetScaledBounds (r, new SizeF (.5f, .5f), BoundsSpecified.All), "A10");
2539                 }
2540
2541                 [Test]
2542                 public void MethodScaleControl ()
2543                 {
2544                         if (TestHelper.RunningOnUnix)
2545                                 Assert.Ignore ("Depends on WM decoration sizes, values correspond to windows");
2546                         
2547                         ScaleForm f = new ScaleForm ();
2548                         f.Location = new Point (5, 10);
2549
2550                         Assert.AreEqual (new Rectangle (5, 10, 300, 300), f.Bounds, "A1");
2551
2552                         f.PublicScaleControl (new SizeF (2.0f, 2.0f), BoundsSpecified.All);
2553                         Assert.AreEqual (new Rectangle (5, 10, 584, 564), f.Bounds, "A2");
2554
2555                         f.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Location);
2556                         Assert.AreEqual (new Rectangle (5, 10, 584, 564), f.Bounds, "A3");
2557
2558                         f.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Size);
2559                         Assert.AreEqual (new Rectangle (5, 10, 300, 300), f.Bounds, "A4");
2560
2561                         f.PublicScaleControl (new SizeF (2.5f, 2.5f), BoundsSpecified.Size);
2562                         Assert.AreEqual (new Rectangle (5, 10, 726, 696), f.Bounds, "A5");
2563
2564                         f.PublicScaleControl (new SizeF (.3f, .3f), BoundsSpecified.Size);
2565                         Assert.AreEqual (new Rectangle (5, 10, 229, 234), f.Bounds, "A6");
2566
2567                         f.Dispose ();
2568                 }
2569
2570                 private class ScaleForm : Form
2571                 {
2572                         public Rectangle PublicGetScaledBounds (Rectangle bounds, SizeF factor, BoundsSpecified specified)
2573                         {
2574                                 return base.GetScaledBounds (bounds, factor, specified);
2575                         }
2576
2577                         public void PublicScaleControl (SizeF factor, BoundsSpecified specified)
2578                         {
2579                                 base.ScaleControl (factor, specified);
2580                         }
2581                 }
2582 #endif
2583                 [Test]
2584                 public void Bug325436 ()
2585                 {
2586                         Form f = new Form ();
2587                         f.ShowInTaskbar = false;
2588                         f.ClientSize = new Size (320, 40);
2589                         f.ControlBox = false;
2590                         f.FormBorderStyle = FormBorderStyle.None;
2591                         f.MaximizeBox = false;
2592                         f.MinimizeBox = false;
2593                         
2594                         f.Show ();
2595                         Assert.AreEqual (new Size (320, 40), f.ClientSize, "A1");
2596                         f.Dispose ();
2597
2598                         f = new Form ();
2599                         f.ShowInTaskbar = false;
2600                         f.ControlBox = false;
2601                         f.FormBorderStyle = FormBorderStyle.None;
2602                         f.MaximizeBox = false;
2603                         f.MinimizeBox = false;
2604                         f.ClientSize = new Size(320, 40);
2605                         
2606                         f.Show ();
2607                         Assert.AreEqual (new Size (320, 40), f.ClientSize, "A2");
2608                         f.Dispose ();
2609                 }
2610
2611 #if NET_2_0
2612                 #region PreferredSize
2613                 [Test]
2614                 public void PreferredSize ()
2615                 {
2616                         PreferredSizeForm form = new PreferredSizeForm ();
2617                         form.AutoSize = true;
2618                         Control control = new Control ();
2619                         form.Controls.Add (control);
2620                         control.Size = new Size (500, 500);
2621                         form.Test ();
2622                         form.Controls.Clear ();
2623                         form.Test2 ();
2624
2625                 }
2626
2627                 private class PreferredSizeForm : Form
2628                 {
2629                         public void Test ()
2630                         {
2631                                 Assert.AreEqual (SizeFromClientSize (new Size (503, 503)), PreferredSize, "1");
2632                         }
2633
2634                         public void Test2 ()
2635                         {
2636                                 Assert.AreEqual (SizeFromClientSize (new Size (0, 0)), PreferredSize, "1");
2637                         }
2638                 }
2639                 #endregion
2640 #endif
2641                 private class MockForm : Form
2642                 {
2643                         public bool CloseOnLoad {
2644                                 get { return _closeOnLoad; }
2645                                 set { _closeOnLoad = value; }
2646                         }
2647
2648                         public bool VisibleOnLoad {
2649                                 get { return _visibleOnLoad; }
2650                         }
2651
2652                         protected override void OnLoad(EventArgs e) {
2653                                 base.OnLoad(e);
2654                                 _visibleOnLoad = Visible;
2655                                 if (CloseOnLoad)
2656                                         Close ();
2657                         }
2658
2659                         private bool _closeOnLoad;
2660                         private bool _visibleOnLoad;
2661                 }
2662
2663                 private class MockButton : Button
2664                 {
2665                         public MockButton (bool notify)
2666                         {
2667                                 _notify = notify;
2668                         }
2669
2670                         public bool Notify {
2671                                 get { return _notify; }
2672                                 set { _notify = value; }
2673                         }
2674
2675                         public bool IsDefaultButton
2676                         {
2677                                 get { return base.IsDefault; }
2678                                 set { base.IsDefault = value; }
2679                         }
2680
2681                         public override void NotifyDefault (bool value)
2682                         {
2683                                 if (Notify)
2684                                         base.NotifyDefault (value);
2685                         }
2686
2687                         private bool _notify;
2688                 }
2689
2690                 private class ButtonControl : IButtonControl
2691                 {
2692                         public DialogResult DialogResult {
2693                                 get { return _dialogResult; }
2694                                 set { _dialogResult = value; }
2695                         }
2696
2697                         public bool IsDefaultButton {
2698                                 get { return _isDefault; }
2699                         }
2700
2701                         public void NotifyDefault (bool value)
2702                         {
2703                                 _isDefault = value;
2704                         }
2705
2706                         public void PerformClick ()
2707                         {
2708                         }
2709
2710                         private bool _isDefault;
2711                         private DialogResult _dialogResult = DialogResult.None;
2712                 }
2713                 
2714 #if NET_2_0
2715                 [Test]
2716                 public void RestoreBounds ()
2717                 {
2718                         Form f = new Form ();
2719                         f.Show ();
2720                         
2721                         Assert.AreEqual (new Size (300, 300), f.RestoreBounds.Size, "A1");
2722                         
2723                         // Move the form
2724                         f.Location = new Point (0, 0);
2725                         Assert.AreEqual (new Rectangle (0, 0, 300, 300), f.RestoreBounds, "A2");
2726                         
2727                         // Resize the form
2728                         f.Size = new Size (250, 250);
2729                         Assert.AreEqual (new Rectangle (0, 0, 250, 250), f.RestoreBounds, "A3");
2730                         
2731                         // Minimize the form
2732                         f.WindowState = FormWindowState.Minimized;
2733                         Assert.AreEqual (new Rectangle (0, 0, 250, 250), f.RestoreBounds, "A4");
2734
2735                         // Move the form (while minimized)
2736                         f.Location = new Point (10, 10);
2737                         Assert.AreEqual (new Rectangle (10, 10, 250, 250), f.RestoreBounds, "A5");
2738
2739                         // Resize the form (while minimized)
2740                         f.Size = new Size (275, 275);
2741                         Assert.AreEqual (new Rectangle (10, 10, 275, 275), f.RestoreBounds, "A6");
2742                         
2743                         // Maximize the form
2744                         f.WindowState = FormWindowState.Maximized;
2745                         Assert.AreEqual (new Rectangle (10, 10, 275, 275), f.RestoreBounds, "A7");
2746
2747                         // Move the form (while maximized)
2748                         f.Location = new Point (20, 20);
2749                         Assert.AreEqual (new Rectangle (20, 20, 275, 275), f.RestoreBounds, "A8");
2750
2751                         // Resize the form (while maximized)
2752                         f.Size = new Size (285, 285);
2753                         Assert.AreEqual (new Rectangle (20, 20, 285, 285), f.RestoreBounds, "A9");
2754                         
2755                         f.Dispose ();
2756                 }
2757                 
2758                 [Test]  // Bug 353827
2759                 public void AutoScaleModeTest ()
2760                 {
2761                         Form f = new Form ();
2762                         
2763                         // AutoScale starts off true
2764                         Assert.AreEqual (true, f.AutoScale, "A1");
2765                         
2766                         // Setting AutoScaleMode turns AutoScale off
2767                         f.AutoScaleMode = AutoScaleMode.Font;
2768                         Assert.AreEqual (false, f.AutoScale, "A2");
2769                         Assert.AreEqual (AutoScaleMode.Font, f.AutoScaleMode, "A3");
2770
2771                         // Changing Font resets AutoScaleBaseSize..
2772                         f.Font = new Font ("Arial", 10);
2773                         Assert.AreEqual (RoundSizeF (Form.GetAutoScaleSize (f.Font)), f.AutoScaleBaseSize, "A4");
2774
2775                         f.Font = new Font ("Arial", 12);
2776                         Assert.AreEqual (RoundSizeF (Form.GetAutoScaleSize (f.Font)), f.AutoScaleBaseSize, "A5");
2777                         
2778                         // ..Until AutoScaleBaseSize is explicitly set
2779                         f.AutoScaleBaseSize = new Size (5, 13);
2780                         Assert.AreEqual (new Size (5, 13), f.AutoScaleBaseSize, "A6");
2781
2782                         f.Font = new Font ("Arial", 14F);
2783                         Assert.IsTrue (RoundSizeF (Form.GetAutoScaleSize (f.Font)) != f.AutoScaleBaseSize, "A5");
2784         
2785                         f.Dispose ();
2786                 }
2787                 
2788                 private Size RoundSizeF (SizeF sizef)
2789                 {
2790                         return new Size ((int)Math.Round (sizef.Width), (int)Math.Round (sizef.Height));
2791                 }
2792                 
2793                 [Test] // Bug 354669
2794                 public void AutoScaleDetails ()
2795                 {
2796                         ProtectedForm f = new ProtectedForm ();
2797                         f.Show ();
2798                         
2799                         f.SuspendLayout ();
2800                         
2801                         // First AutoScaleMode shouldn't reset AutoScaleDimensions
2802                         f.AutoScaleDimensions = new SizeF (3F, 3F);
2803                         f.AutoScaleMode = AutoScaleMode.Font;
2804                         Assert.AreEqual (new SizeF (3F, 3F), f.AutoScaleDimensions, "A1");
2805                         
2806                         // Subsequent calls will reset it to 0, 0
2807                         f.AutoScaleMode = AutoScaleMode.Dpi;
2808                         Assert.AreEqual (SizeF.Empty, f.AutoScaleDimensions, "A2");
2809
2810                         f.ResumeLayout ();
2811                         
2812                         // CurrentAutoScaleDimensions should be nonzero
2813                         Assert.IsFalse (f.CurrentAutoScaleDimensions == SizeF.Empty, "A3");
2814                         
2815                         // AutoScaleDimensions and CurrentAutoScaleDimensions should match after ResumeLayout
2816                         Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A4");
2817
2818                         // CurrentAutoScaleDimensions should match AutoScaleDimensions for AutoScaleMode.None
2819                         f.SuspendLayout ();
2820                         f.AutoScaleMode = AutoScaleMode.None;
2821                         f.AutoScaleDimensions = new SizeF (5F, 5F);
2822
2823                         Assert.AreEqual (new SizeF (5F, 5F), f.AutoScaleDimensions, "A5");
2824                         Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A6");
2825
2826                         // ResumeLayout changes nothing
2827                         f.ResumeLayout ();
2828
2829                         Assert.AreEqual (new SizeF (5F, 5F), f.AutoScaleDimensions, "A7");
2830                         Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A8");
2831
2832                         // AutoScaleFactor should be ~2,2 if PerformAutoScale hasn't run
2833                         f.ClientSize = new Size (150, 150);
2834                         f.SuspendLayout ();
2835                         f.AutoScaleMode = AutoScaleMode.Dpi;
2836                         f.AutoScaleDimensions = new SizeF (f.CurrentAutoScaleDimensions.Width / 2F, f.CurrentAutoScaleDimensions.Height / 2F);
2837                         f.ClientSize = new Size (200, 200);
2838
2839                         Assert.AreEqual (new Size (2, 2), RoundSizeF (f.GetPublicAutoScaleFactor ()), "A9");
2840
2841                         // AutoScaleFactor should be 1 after ResumeLayout
2842                         f.ResumeLayout ();
2843
2844                         Assert.AreEqual (new SizeF (1F, 1F), f.GetPublicAutoScaleFactor (), "A10");
2845                         Assert.AreEqual (new Size (400, 400), f.ClientSize, "A11");
2846                         
2847                         // PerformAutoScale happens immediately when layout not suspended
2848                         f.ClientSize = new Size (125, 125);
2849                         f.AutoScaleDimensions = new SizeF (f.CurrentAutoScaleDimensions.Width / 2F, f.CurrentAutoScaleDimensions.Height / 2F);
2850                         Assert.AreEqual (new Size (250, 250), f.ClientSize, "A12");
2851                         
2852                         f.Dispose ();
2853                 }
2854                 
2855                 private class ProtectedForm : Form
2856                 {
2857                         public SizeF GetPublicAutoScaleFactor ()
2858                         {
2859                                 return AutoScaleFactor;
2860                         }
2861                 }
2862                 
2863                 [Test] // Bug #355703
2864                 public void AutoScaleSticks ()
2865                 {
2866                         Form f = new Form ();
2867
2868                         f.AutoScale = false;
2869                         Assert.AreEqual (false, f.AutoScale, "A1");
2870
2871                         f.AutoScale = true;
2872                         Assert.AreEqual (true, f.AutoScale, "A2");
2873                         
2874                         f.AutoScaleMode = AutoScaleMode.None;
2875                         Assert.AreEqual (false, f.AutoScale, "A3");
2876                 }
2877 #endif
2878
2879                 [Test] // Bug #359098
2880                 public void AutoScaleBounds ()
2881                 {
2882                         AutoScaleForm a = new AutoScaleForm (false);
2883                         a.Show ();
2884                         Assert.AreEqual (new Size (213, 121), a.ClientSize, "A0");
2885                         Assert.AreEqual (new Rectangle (  5, 107, 132,  9), new Rectangle (a.hScrollBar1.Location, a.hScrollBar1.Size), "A1");
2886                         Assert.AreEqual (new Rectangle (151,  74,  60, 44), new Rectangle (a.treeView1.Location, a.treeView1.Size), "A2");
2887                         Assert.AreEqual (new Rectangle (197,  21,   9, 39), new Rectangle (a.vScrollBar1.Location, a.vScrollBar1.Size), "A3");
2888                         Assert.AreEqual (new Rectangle (139,  21,  54, 49), new Rectangle (a.listView1.Location, a.listView1.Size), "A4");
2889                         Assert.AreEqual (new Rectangle ( 70,   5,  65, 37), new Rectangle (a.textBox2.Location, a.textBox2.Size), "A5");
2890                         Assert.AreEqual (new Rectangle (139,   5,  70,  0), new Rectangle (a.comboBox1.Location, new Size (a.comboBox1.Width, 0)), "A6");
2891                         Assert.AreEqual (new Rectangle (  5,  77,  43, 13), new Rectangle (a.button2.Location, a.button2.Size), "A7");
2892                         Assert.AreEqual (new Rectangle ( 70,  44,  65, 37), new Rectangle (a.richTextBox1.Location, a.richTextBox1.Size), "A8");
2893                         Assert.AreEqual (new Rectangle ( 53,  86,  21,  7), new Rectangle (a.label1.Location,a.label1.Size), "A9");
2894                         Assert.AreEqual (new Rectangle ( 65,  84,  58,  0), new Rectangle (a.textBox1.Location, new Size (a.textBox1.Width, 0)), "A10");
2895                         Assert.AreEqual (new Rectangle (  5,  63,  43, 13), new Rectangle (a.button1.Location, a.button1.Size), "A11");
2896                         Assert.AreEqual (new Rectangle (  5,   5,  60, 47), new Rectangle (a.listBox1.Location, a.listBox1.Size), "A12");
2897                         a.Dispose ();
2898
2899 #if NET_2_0
2900                         a = new AutoScaleForm (true);
2901                         a.Show ();
2902                         Assert.AreEqual (new Size (184, 104), a.ClientSize, "B0");
2903                         Assert.AreEqual (new Rectangle (  4, 92, 114, 16), new Rectangle (a.hScrollBar1.Location, a.hScrollBar1.ClientSize), "B1");
2904                         Assert.AreEqual (new Rectangle (130, 64,  50, 36), new Rectangle (a.treeView1.Location, a.treeView1.ClientSize), "B2");
2905                         Assert.AreEqual (new Rectangle (170, 18,  16, 34), new Rectangle (a.vScrollBar1.Location, a.vScrollBar1.ClientSize), "B3");
2906                         Assert.AreEqual (new Rectangle (120, 18,  44, 40), new Rectangle (a.listView1.Location, a.listView1.ClientSize), "B4");
2907                         Assert.AreEqual (new Rectangle ( 60,  4,  54, 30), new Rectangle (a.textBox2.Location, a.textBox2.ClientSize), "B5");
2908                         Assert.AreEqual (new Rectangle (120,  4,  62,  0), new Rectangle (a.comboBox1.Location, new Size (a.comboBox1.ClientSize.Width, 0)), "B6");
2909                         Assert.AreEqual (new Rectangle (  4, 66,  38, 12), new Rectangle (a.button2.Location, a.button2.ClientSize), "B7");
2910                         Assert.AreEqual (new Rectangle ( 60, 38,  54, 30), new Rectangle (a.richTextBox1.Location, a.richTextBox1.ClientSize), "B8");
2911                         Assert.AreEqual (new Rectangle ( 46, 74,  18,  6), new Rectangle (a.label1.Location,a.label1.ClientSize), "B9");
2912                         Assert.AreEqual (new Rectangle ( 56, 72,  48,  0), new Rectangle (a.textBox1.Location, new Size (a.textBox1.ClientSize.Width, 0)), "B10");
2913                         Assert.AreEqual (new Rectangle (  4, 54,  38, 12), new Rectangle (a.button1.Location, a.button1.ClientSize), "B11");
2914                         Assert.AreEqual (new Rectangle (  4,  4,  50, 39), new Rectangle (a.listBox1.Location, a.listBox1.ClientSize), "B12");
2915                         a.Dispose ();
2916 #endif
2917                 }
2918
2919                 [Test]
2920                 public void SettingIconToNull ()
2921                 {
2922                         Form form = new Form ();
2923                         Assert.IsNotNull (form.Icon, "1");
2924                         form.Icon = null;
2925                         Assert.IsNotNull (form.Icon, "2");
2926                 }
2927
2928                 [Test]
2929                 [Category ("NotWorking")]
2930                 public void MinimizedWindowSize ()
2931                 {
2932                         Form form = new Form ();
2933                         form.WindowState = FormWindowState.Minimized;
2934                         form.Show ();
2935                         Assert.AreEqual (SystemInformation.MinimizedWindowSize, form.Size, "1");
2936                         form.Close ();
2937                         form = new Form ();
2938                         form.Show ();
2939                         form.WindowState = FormWindowState.Minimized;
2940                         Assert.AreEqual (SystemInformation.MinimizedWindowSize, form.Size, "2");
2941                         form.Close ();
2942                 }
2943         }
2944
2945         public class TimeBombedForm : Form
2946         {
2947                 public Timer timer;
2948                 public bool CloseOnPaint;
2949                 public string Reason;
2950                 public TimeBombedForm ()
2951                 {
2952                         timer = new Timer ();
2953                         timer.Interval = 500;
2954                         timer.Tick += new EventHandler (timer_Tick);
2955                         timer.Start ();
2956                 }
2957
2958                 void timer_Tick (object sender, EventArgs e)
2959                 {
2960                         Reason = "Bombed";
2961                         Close ();
2962                 }
2963
2964                 protected override void OnPaint (PaintEventArgs pevent)
2965                 {
2966                         base.OnPaint (pevent);
2967                         if (CloseOnPaint) {
2968                                 Reason = "OnPaint";
2969                                 Close ();
2970                         }
2971                 }
2972         }
2973
2974         public class AutoScaleForm : Form
2975         {
2976                 public ListBox listBox1 = new ListBox ();
2977                 public ComboBox comboBox1 = new ComboBox ();
2978                 public Button button1 = new Button ();
2979                 public Button button2 = new Button ();
2980                 public Label label1 = new Label ();
2981                 public TextBox textBox1 = new TextBox ();
2982                 public TextBox textBox2 = new TextBox ();
2983                 public RichTextBox richTextBox1 = new RichTextBox ();
2984                 public ListView listView1 = new ListView ();
2985                 public TreeView treeView1 = new TreeView ();
2986                 public VScrollBar vScrollBar1 = new VScrollBar ();
2987                 public HScrollBar hScrollBar1 = new HScrollBar ();
2988
2989                 public AutoScaleForm (bool use_new_auto_scale)
2990                 {
2991                         ShowInTaskbar = false;
2992                         
2993                         SuspendLayout ();
2994
2995                         listBox1.IntegralHeight = false;
2996                         listBox1.SetBounds (8, 8, 104, 82);
2997                         comboBox1.SetBounds (240, 8, 121, 21);
2998                         button1.SetBounds (8, 108, 75, 23);
2999                         button2.SetBounds (8, 132, 75, 23);
3000                         label1.SetBounds (92, 148, 35, 13);
3001                         textBox1.SetBounds (112, 144, 100, 20);
3002                         textBox2.Multiline = true;
3003                         textBox2.SetBounds (120, 8, 112, 64);
3004                         richTextBox1.SetBounds (120, 76, 112, 64);
3005                         listView1.SetBounds (240, 36, 92, 84);
3006                         treeView1.SetBounds (260, 128, 104, 76);
3007                         vScrollBar1.SetBounds (340, 36, 16, 68);
3008                         hScrollBar1.SetBounds (8, 184, 228, 16);
3009
3010                         ClientSize = new Size (368, 209);
3011
3012                         Controls.AddRange ( new Control [] { listBox1, comboBox1, button1, button2, label1, textBox1,
3013                                 textBox2, richTextBox1, listView1, treeView1, vScrollBar1, hScrollBar1 } );
3014
3015                         if (use_new_auto_scale) {
3016 #if NET_2_0
3017                                 AutoScaleMode = AutoScaleMode.Dpi;
3018                                 SizeF s = CurrentAutoScaleDimensions;
3019                                 AutoScaleDimensions = new SizeF (s.Width * 2, s.Height * 2);
3020 #endif
3021                         }
3022                         else {
3023                                 AutoScale = true;
3024                                 SizeF s = Form.GetAutoScaleSize (Font);
3025                                 AutoScaleBaseSize = new Size ((int)Math.Round (s.Width) * 2, (int)s.Height * 2);
3026                         }
3027
3028                         ResumeLayout (false);
3029                         PerformLayout ();
3030                 }
3031         }
3032 }