2008-01-18 Jonathan Pobst <monkey@jpobst.com>
[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
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                                 Assert.AreEqual (1, log.CountEvents ("Closing"), "#B1");
660 #if NET_2_0
661                                 Assert.AreEqual (1, log.CountEvents ("FormClosing"), "#B2");
662 #endif
663                                 Assert.AreEqual (1, log.CountEvents ("HandleDestroyed"), "#B3");
664
665                                 Assert.AreEqual (1, log.CountEvents ("Closed"), "#B4");
666 #if NET_2_0
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] // bug #80791
1147                 public void ClientSizeTest ()
1148                 {
1149                         Form form = new Form ();
1150                         Assert.IsFalse (form.ClientSize == form.Size);
1151                 }
1152
1153                 [Test] // bug #80574
1154                 [Category ("NotWorking")]
1155                 public void FormBorderStyleTest ()
1156                 {
1157                         Form form = new Form ();
1158                         Rectangle boundsBeforeBorderStyleChange = form.Bounds;
1159                         Rectangle clientRectangleBeforeBorderStyleChange = form.ClientRectangle;
1160                         form.FormBorderStyle = FormBorderStyle.None;
1161                         Assert.AreEqual (form.Bounds, boundsBeforeBorderStyleChange, "#A1");
1162                         Assert.AreEqual (form.ClientRectangle, clientRectangleBeforeBorderStyleChange, "#A2");
1163
1164                         form.Visible = true;
1165                         form.FormBorderStyle = FormBorderStyle.Sizable;
1166                         boundsBeforeBorderStyleChange = form.Bounds;
1167                         clientRectangleBeforeBorderStyleChange = form.ClientRectangle;
1168                         form.FormBorderStyle = FormBorderStyle.None;
1169                         Assert.IsFalse (form.Bounds == boundsBeforeBorderStyleChange, "#B1");
1170                         Assert.AreEqual (form.ClientRectangle, clientRectangleBeforeBorderStyleChange, "#B2");
1171
1172                         form.Visible = false;
1173                         form.FormBorderStyle = FormBorderStyle.Sizable;
1174                         boundsBeforeBorderStyleChange = form.Bounds;
1175                         clientRectangleBeforeBorderStyleChange = form.ClientRectangle;
1176                         form.FormBorderStyle = FormBorderStyle.None;
1177                         Assert.IsFalse (form.Bounds == boundsBeforeBorderStyleChange, "#C1");
1178                         Assert.AreEqual (form.ClientRectangle, clientRectangleBeforeBorderStyleChange, "#C2");
1179                 }
1180
1181                 [Test]
1182                 [Category ("NotWorking")]
1183                 public void MaximizedParentedFormTest ()
1184                 {
1185                         using (Form Main = new Form ()) {
1186                                 Form Child = new Form ();
1187                                 Child.TopLevel = false;
1188                                 Main.Controls.Add (Child);
1189                                 Main.ShowInTaskbar = false;
1190                                 Main.Show ();
1191                                 
1192                                 Child.WindowState = FormWindowState.Maximized;
1193                                 Child.Visible = true;
1194                                 // The exact negative value depends on the border with, but it should always be < 0.
1195                                 Assert.IsTrue (Child.Location.X < 0 && Child.Location.Y < 0, "#A1");
1196                         }
1197                 }
1198                 [Test]
1199                 [Category ("NotWorking")]
1200                 public void ParentedFormEventTest ()
1201                 {
1202
1203                         using (Form Main = new Form ()) {
1204                                 Form Child = new Form ();
1205                                 Child.TopLevel = false;
1206                                 Child.Visible = true;
1207                                 Main.ShowInTaskbar = false;
1208                                 Main.Show ();
1209
1210                                 EventLogger log = new EventLogger (Child);
1211                                 Assert.AreEqual (true, Child.Visible, "#A0");
1212                                 Main.Controls.Add (Child);
1213                                 Assert.AreEqual (true, Child.Visible, "#B0");
1214                                 Assert.AreEqual ("ParentChanged;BindingContextChanged;Layout;VisibleChanged;BindingContextChanged;BindingContextChanged", log.EventsJoined (), "#B1");
1215                         }
1216                 }
1217                 [Test]
1218                 [NUnit.Framework.Category ("NotWorking")]
1219                 public void FormCreateParamsStyleTest ()
1220                 {
1221                         Form frm;
1222                         
1223                         using (frm = new Form ()) {
1224                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles) TestHelper.GetCreateParams (frm).Style), "#01-Style");
1225                                 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");
1226                         }
1227
1228                         using (frm = new Form ()) {
1229                                 frm.AllowDrop = !frm.AllowDrop;
1230                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#02-Style");
1231                                 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");
1232                         }
1233
1234                         using (frm = new Form ()) {
1235                                 frm.AllowTransparency = !frm.AllowTransparency;
1236                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#03-Style");
1237                                 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");
1238                         }
1239
1240                         using (frm = new Form ()) {
1241                                 frm.Opacity = 0.50;
1242                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#04-Style");
1243                                 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");
1244                         }
1245
1246                         using (frm = new Form ()) {
1247                                 frm.TransparencyKey = Color.Cyan;
1248                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#05-Style");
1249                                 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");
1250                         }
1251                         
1252                         using (frm = new Form ()) {
1253                                 frm.CausesValidation = !frm.CausesValidation;
1254                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#06-Style");
1255                                 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");
1256                         }
1257
1258                         using (frm = new Form ()) {
1259                                 frm.ControlBox = !frm.ControlBox;
1260                                 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");
1261                                 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");
1262                         }
1263
1264                         using (frm = new Form ()) {
1265                                 frm.Enabled = true;
1266                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#08-Style");
1267                                 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");
1268                         }
1269
1270                         using (frm = new Form ()) {
1271                                 frm.FormBorderStyle = FormBorderStyle.Fixed3D;
1272                                 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");
1273                                 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");
1274                         }
1275
1276                         using (frm = new Form ()) {
1277                                 frm.FormBorderStyle = FormBorderStyle.FixedDialog;
1278                                 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");
1279                                 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");
1280                         }
1281
1282                         using (frm = new Form ()) {
1283                                 frm.FormBorderStyle = FormBorderStyle.FixedSingle;
1284                                 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");
1285                                 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");
1286                         }
1287
1288                         using (frm = new Form ()) {
1289                                 frm.FormBorderStyle = FormBorderStyle.FixedToolWindow;
1290                                 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");
1291                                 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");
1292                         }
1293
1294                         using (frm = new Form ()) {
1295                                 frm.FormBorderStyle = FormBorderStyle.None;
1296                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#14-Style");
1297                                 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");
1298                         }
1299
1300                         using (frm = new Form ()) {
1301                                 frm.FormBorderStyle = FormBorderStyle.Sizable;
1302                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#15-Style");
1303                                 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");
1304                         }
1305
1306                         using (frm = new Form ()) {
1307                                 frm.FormBorderStyle = FormBorderStyle.SizableToolWindow;
1308                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#16-Style");
1309                                 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");
1310                         }
1311
1312                         using (frm = new Form ()) {
1313                                 frm.HelpButton = !frm.HelpButton;
1314                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#17-Style");
1315                                 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");
1316                         }
1317
1318                         using (frm = new Form ()) {
1319                                 frm.Icon = null;
1320                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#18-Style");
1321                                 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");
1322                         }
1323
1324                         using (frm = new Form ()) {
1325                                 frm.Icon = SystemIcons.Asterisk;
1326                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#19-Style");
1327                                 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");
1328                         }
1329
1330                         using (frm = new Form ()) {
1331                                 frm.IsMdiContainer = !frm.IsMdiContainer;
1332                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#20-Style");
1333                                 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");
1334                         }
1335
1336                         using (frm = new Form ()) {
1337                                 frm.MaximizeBox = !frm.MaximizeBox;
1338                                 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");
1339                                 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");
1340                         }
1341
1342                         using (frm = new Form ()) {
1343                                 frm.MinimizeBox = !frm.MinimizeBox;
1344                                 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");
1345                                 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");
1346                         }
1347 #if NET_2_0
1348                         using (frm = new Form ()) {
1349                                 frm.ShowIcon = !frm.ShowIcon;
1350                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#23-Style");
1351                                 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");
1352                         }
1353 #endif          
1354                         using (frm = new Form ()) {
1355                                 frm.ShowInTaskbar = !frm.ShowInTaskbar;
1356                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#24-Style");
1357                                 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#24-ExStyle");
1358                         }
1359
1360
1361                         using (frm = new Form ()) {
1362                                 frm.TabStop = !frm.TabStop;
1363                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#25-Style");
1364                                 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");
1365                         }
1366
1367                         using (frm = new Form ()) {
1368                                 frm.TopLevel = !frm.TopLevel;
1369                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_CHILD, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#26-Style");
1370                                 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");
1371                         }
1372
1373                         using (frm = new Form ()) {
1374                                 frm.Visible = !frm.Visible;
1375                                 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#27-Style");
1376                                 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");
1377                         }
1378
1379                         using (frm = new Form ()) {
1380                                 frm.ControlBox = false;
1381                                 frm.Text = "";
1382                                 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");
1383                                 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");
1384                         }
1385                 }
1386                 
1387                 [Test]
1388                 public void FormParentedTest ()
1389                 {
1390                         using (Form frm = new Form ()) {
1391                                 using (Form frm2 = new Form ()) {
1392                                         frm2.TopLevel = false;
1393                                         frm.ShowInTaskbar = false;
1394                                         frm2.ShowInTaskbar = false;
1395                                         frm2.Visible = true;
1396                                         frm.Visible = true;
1397                                         
1398                                         EventLogger log = new EventLogger (frm);
1399                                         EventLogger log2 = new EventLogger (frm2);
1400                                         
1401                                         frm.Controls.Add (frm2);
1402
1403                                         Assert.IsTrue (log2.EventRaised ("ParentChanged"), "#C1");
1404                                         Assert.IsTrue (log.EventRaised ("ControlAdded"), "#P1");
1405                                         Assert.AreSame (frm, frm2.Parent, "#02");
1406                                 }
1407                         }
1408                 }
1409                 
1410                 [Test]
1411                 public void FormPropertyTest ()
1412                 {
1413                         Form myform = new Form ();
1414                         myform.Visible = true;
1415                         myform.Text = "NewForm";
1416                         myform.Name = "FormTest";
1417                         Assert.IsNull (myform.ActiveMdiChild, "#2"); 
1418                         Assert.IsFalse (myform.AutoScale, "#3");
1419                         Assert.IsNull (myform.CancelButton, "#6");
1420                         Assert.IsTrue (myform.ControlBox, "#9");
1421                         Assert.IsTrue (myform.DesktopBounds.X > 0, "#10a");
1422                         Assert.IsTrue (myform.DesktopBounds.Y > 0, "#10b");
1423                         Assert.AreEqual (300, myform.DesktopBounds.Height, "#10c");
1424                         Assert.AreEqual (300, myform.DesktopBounds.Width, "#10d");
1425                         Assert.IsTrue (myform.DesktopLocation.X > 0, "#11a");
1426                         Assert.IsTrue (myform.DesktopLocation.Y > 0, "#11b");
1427                         Assert.AreEqual (DialogResult.None, myform.DialogResult, "#12");
1428                         Assert.AreEqual (FormBorderStyle.Sizable, myform.FormBorderStyle, "#13");
1429                         Assert.IsFalse (myform.HelpButton, "#14");
1430                         Assert.AreEqual ("System.Drawing.Icon", myform.Icon.GetType ().ToString (), "#15");
1431                         Assert.IsFalse (myform.IsMdiChild, "#16");
1432                         Assert.IsFalse (myform.IsMdiContainer, "#17");
1433                         Assert.IsFalse (myform.KeyPreview, "#18");
1434                         Assert.IsTrue (myform.MaximizeBox, "#19");
1435                         Assert.AreEqual (0, myform.MaximumSize.Height, "#20a");
1436                         Assert.AreEqual (0, myform.MaximumSize.Width, "#20b");
1437                         Assert.AreEqual (0, myform.MdiChildren.Length, "#21a");
1438                         Assert.AreEqual (1, myform.MdiChildren.Rank, "#21b");
1439                         Assert.IsFalse (myform.MdiChildren.IsSynchronized, "#21c");
1440                         Assert.IsNull (myform.MdiParent, "#22");
1441                         Assert.IsNull (myform.Menu, "#23");
1442                         Assert.IsNull (myform.MergedMenu, "#24");
1443                         Assert.IsTrue (myform.MinimizeBox, "#25");
1444                         Assert.AreEqual (0, myform.MinimumSize.Height, "#26a");
1445                         Assert.AreEqual (0, myform.MinimumSize.Width, "#26b");
1446                         Assert.IsTrue (myform.MinimumSize.IsEmpty, "#26c");
1447                         Assert.IsFalse (myform.Modal, "#27");
1448                         Assert.AreEqual (1, myform.Opacity, "#28");
1449                         Assert.AreEqual (0, myform.OwnedForms.Length, "#29a");
1450                         Assert.AreEqual (1, myform.OwnedForms.Rank, "#29b");
1451                         Assert.IsNull (myform.Owner, "#30");
1452                         Assert.IsTrue (myform.ShowInTaskbar, "#31");
1453                         Assert.AreEqual (300, myform.Size.Height, "#32a");
1454                         Assert.AreEqual (300, myform.Size.Width, "#32b");
1455                         Assert.AreEqual (SizeGripStyle.Auto, myform.SizeGripStyle, "#33");
1456                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, myform.StartPosition, "#34");
1457                         Assert.IsTrue (myform.TopLevel, "#35");
1458                         Assert.IsFalse (myform.TopMost, "#36");
1459                         Assert.AreEqual (Color.Empty, myform.TransparencyKey, "#37");
1460                         Assert.AreEqual (FormWindowState.Normal, myform.WindowState, "#38");
1461                         Assert.AreEqual (ImeMode.NoControl, myform.ImeMode, "#39");
1462                         myform.Dispose ();
1463                 }
1464
1465                 [Test]
1466                 [Category ("NotWorking")]
1467                 public void ActivateTest ()
1468                 {
1469                         Form myform = new Form ();
1470                         myform.ShowInTaskbar = false;
1471                         myform.Visible = true;
1472                         myform.Text = "NewForm";
1473                         myform.Name = "FormTest";
1474                         myform.Activate ();
1475                         Assert.AreEqual (true, myform.Focus (), "#40");
1476                         myform.Dispose ();
1477                 }
1478
1479                 [Test]
1480                 public void AddOwnedFormTest ()
1481                 {
1482                         Form parent = new Form ();
1483                         parent.ShowInTaskbar = false;
1484                         parent.Text = "NewParent";
1485                         Form ownedForm = new Form ();
1486                         ownedForm.ShowInTaskbar = false;
1487                         ownedForm.Text = "Owned Form";
1488                         parent.AddOwnedForm (ownedForm);
1489                         ownedForm.Show ();
1490                         Assert.AreEqual ("NewParent", ownedForm.Owner.Text, "#41");
1491                         ownedForm.Dispose ();
1492                         parent.Dispose ();
1493                 }
1494
1495                 [Test] // bug #80020
1496                 public void IsHandleCreated ()
1497                 {
1498                         Form main = new Form ();
1499                         main.Name = "main";
1500                         main.IsMdiContainer = true;
1501                         main.ShowInTaskbar = false;
1502                         Assert.IsFalse (main.IsHandleCreated, "#1");
1503
1504                         Form child = new Form ();
1505                         child.MdiParent = main;
1506                         child.WindowState = FormWindowState.Maximized;
1507                         Assert.IsFalse (main.IsHandleCreated, "#2");
1508
1509                         child.Show ();
1510                         Assert.IsFalse (child.IsHandleCreated, "#3");
1511                         Assert.IsFalse (main.IsHandleCreated, "#4");
1512
1513                         main.Show ();
1514                         Assert.IsTrue (child.IsHandleCreated, "#5");
1515                         Assert.IsTrue (main.IsHandleCreated, "#6");
1516
1517                         child.Dispose ();
1518                         main.Dispose ();
1519                 }
1520
1521                 [Test]
1522                 public void RemoveOwnedFormTest ()
1523                 {
1524                         Form myform = new Form ();
1525                         myform.ShowInTaskbar = false;
1526                         myform.Text = "NewForm";
1527                         myform.Name = "FormTest";
1528                         myform.RemoveOwnedForm (myform);
1529                         myform.Show ();
1530                         Assert.AreEqual (null, myform.Owner, "#44");
1531                         myform.Dispose ();
1532                 }
1533
1534                 [Test]
1535                 public void SetDesktopBoundsTest ()
1536                 {
1537                         Form myform = new Form ();
1538                         myform.ShowInTaskbar = false;
1539                         myform.Visible = true;
1540                         myform.Text = "NewForm";
1541                         myform.Name = "FormTest";
1542                         myform.SetDesktopBounds (10, 10, 200 , 200);
1543                         Assert.AreEqual (200, myform.DesktopBounds.Height, "#45");
1544                         myform.Dispose ();
1545                 }
1546
1547                 [Test]
1548                 public void SetDesktopLocationTest ()
1549                 {
1550                         Form myform = new Form ();
1551                         myform.ShowInTaskbar = false;
1552                         myform.Visible = true;
1553                         myform.Text = "NewForm";
1554                         myform.Name = "FormTest";
1555                         myform.SetDesktopLocation (10, 10);
1556                         Assert.AreEqual (10, myform.DesktopLocation.X, "#46");
1557                         myform.Dispose ();
1558                 }
1559
1560                 [Test]
1561                 public void SetDialogResultOutOfRange ()
1562                 {
1563                         Form myform = new Form ();
1564                         myform.ShowInTaskbar = false;
1565                         try {
1566                                 myform.DialogResult = (DialogResult) (-1);
1567                                 Assert.Fail ("#48");
1568                         } catch (InvalidEnumArgumentException) {
1569                         }
1570
1571                         try {
1572                                 myform.DialogResult = (DialogResult) ((int) DialogResult.No + 1);
1573                                 Assert.Fail ("#49");
1574                         } catch (InvalidEnumArgumentException) {
1575                         }
1576                         myform.Dispose ();
1577                 }
1578
1579                 void myform_set_dialogresult (object sender, EventArgs e)
1580                 {
1581                         Form f = (Form)sender;
1582
1583                         f.DialogResult = DialogResult.OK;
1584                 }
1585
1586                 void myform_close (object sender, EventArgs e)
1587                 {
1588                         Form f = (Form)sender;
1589
1590                         f.Close();
1591                 }
1592
1593                 [Test]
1594                 public void SetDialogResult ()
1595                 {
1596                         Form myform = new Form ();
1597                         myform.ShowInTaskbar = false;
1598                         myform.Visible = true;
1599
1600                         myform.DialogResult = DialogResult.Cancel;
1601
1602                         Assert.IsTrue (myform.Visible, "A1");
1603                         Assert.IsFalse (myform.IsDisposed, "A2");
1604
1605                         myform.Close ();
1606
1607                         Assert.IsFalse (myform.Visible, "A3");
1608                         Assert.IsTrue (myform.IsDisposed, "A4");
1609
1610                         DialogResult result;
1611
1612                         myform = new Form ();
1613                         myform.ShowInTaskbar = false;
1614                         myform.VisibleChanged += new EventHandler (myform_set_dialogresult);
1615                         result = myform.ShowDialog ();
1616
1617                         Assert.AreEqual (result, DialogResult.OK, "A5");
1618                         Assert.IsFalse (myform.Visible, "A6");
1619                         Assert.IsFalse (myform.IsDisposed, "A7");
1620                         myform.Dispose ();
1621                         
1622                         myform = new Form ();
1623                         myform.ShowInTaskbar = false;
1624                         myform.VisibleChanged += new EventHandler (myform_close);
1625                         result = myform.ShowDialog ();
1626
1627                         Assert.AreEqual (result, DialogResult.Cancel, "A8");
1628                         Assert.IsFalse (myform.Visible, "A9");
1629                         Assert.IsFalse (myform.IsDisposed, "A10");
1630                         
1631                         myform.Dispose ();
1632                 }
1633
1634                 [Test]
1635                 public void ShowDialog_Child ()
1636                 {
1637                         Form main = new Form ();
1638                         main.IsMdiContainer = true;
1639                         Form child = new Form ();
1640                         child.MdiParent = main;
1641                         try {
1642                                 child.ShowDialog ();
1643                                 Assert.Fail ("#1");
1644                         } catch (InvalidOperationException ex) {
1645                                 // Forms that are not top level forms cannot be displayed as a
1646                                 // modal dialog. Remove the form from any parent form before 
1647                                 // calling ShowDialog.
1648                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1649                                 Assert.IsNull (ex.InnerException, "#3");
1650                                 Assert.IsNotNull (ex.Message, "#4");
1651                         }
1652                         Assert.IsNull (child.Owner, "#5");
1653                         child.Dispose ();
1654                         main.Dispose ();
1655                 }
1656
1657                 [Test]
1658                 public void ShowDialog_Disabled ()
1659                 {
1660                         Form form = new Form ();
1661                         form.Enabled = false;
1662                         try {
1663                                 form.ShowDialog ();
1664                                 Assert.Fail ("#A1");
1665                         } catch (InvalidOperationException ex) {
1666                                 // Forms that are not enabled cannot be displayed as a modal
1667                                 // dialog. Set the form's enabled property to true before
1668                                 // calling ShowDialog.
1669                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1670                                 Assert.IsNull (ex.InnerException, "#A3");
1671                                 Assert.IsNotNull (ex.Message, "#A4");
1672                         }
1673                         Assert.IsNull (form.Owner, "#A5");
1674                         form.Dispose ();
1675
1676                         Form main = new Form ();
1677                         form = new Form ();
1678                         form.Owner = main;
1679                         form.Enabled = false;
1680                         try {
1681                                 form.ShowDialog ();
1682                                 Assert.Fail ("#B1");
1683                         } catch (InvalidOperationException) {
1684                         }
1685                         Assert.IsNotNull (form.Owner, "#B2");
1686                         Assert.AreSame (main, form.Owner, "#B3");
1687                         form.Dispose ();
1688                         main.Dispose ();
1689                 }
1690
1691                 [Test]
1692                 [Category ("NotWorking")]
1693                 public void ShowDialog_Owner_Circular ()
1694                 {
1695                         Form main = new Form ();
1696                         Form child = new Form ();
1697                         child.Owner = main;
1698                         try {
1699                                 main.ShowDialog (child);
1700                                 Assert.Fail ("#1");
1701                         } catch (ArgumentException ex) {
1702                                 // A circular control reference has been made. A control cannot
1703                                 // be owned or parented to itself
1704                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1705                                 Assert.IsNull (ex.InnerException, "#3");
1706                                 Assert.IsNotNull (ex.Message, "#4");
1707                                 Assert.IsNull (ex.ParamName, "#5");
1708                         }
1709                         Assert.IsNull (main.Owner, "#6");
1710                         main.Dispose ();
1711                         child.Dispose ();
1712                 }
1713
1714                 [Test] // bug #80773
1715                 public void ShowDialog_Owner_Self ()
1716                 {
1717                         Form form = new Form ();
1718                         try {
1719                                 form.ShowDialog (form);
1720                                 Assert.Fail ("#A1");
1721                         } catch (ArgumentException ex) {
1722                                 // Forms cannot own themselves or their owners
1723                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1724                                 Assert.IsNull (ex.InnerException, "#A3");
1725                                 Assert.IsNotNull (ex.Message, "#A4");
1726                                 Assert.IsNotNull (ex.ParamName, "#A5");
1727                                 Assert.AreEqual ("owner", ex.ParamName, "#A6");
1728                         }
1729                         Assert.IsNull (form.Owner, "#A7");
1730                         form.Dispose ();
1731
1732                         Form main = new Form ();
1733                         form = new Form ();
1734                         form.Owner = main;
1735                         try {
1736                                 form.ShowDialog (form);
1737                                 Assert.Fail ("#B1");
1738                         } catch (ArgumentException) {
1739                         }
1740                         Assert.IsNotNull (form.Owner);
1741                         Assert.AreSame (main, form.Owner, "#B2");
1742                         form.Dispose ();
1743                         main.Dispose ();
1744                 }
1745
1746                 [Test]
1747                 public void ShowDialog_Visible ()
1748                 {
1749                         Form form = new Form ();
1750                         form.ShowInTaskbar = false;
1751                         form.Visible = true;
1752                         try {
1753                                 form.ShowDialog ();
1754                                 Assert.Fail ("#A1");
1755                         } catch (InvalidOperationException ex) {
1756                                 // Forms that are already visible cannot be displayed as a modal
1757                                 // dialog. Set the form's visible property to false before 
1758                                 // calling ShowDialog.
1759                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1760                                 Assert.IsNull (ex.InnerException, "#A3");
1761                                 Assert.IsNotNull (ex.Message, "#A4");
1762                         }
1763                         Assert.IsNull (form.Owner, "#A5");
1764                         form.Dispose ();
1765
1766                         Form main = new Form ();
1767                         form = new Form ();
1768                         form.Owner = main;
1769                         form.Visible = true;
1770                         try {
1771                                 form.ShowDialog ();
1772                                 Assert.Fail ("#B1");
1773                         } catch (InvalidOperationException) {
1774                         }
1775                         Assert.IsNotNull (form.Owner, "#B2");
1776                         Assert.AreSame (main, form.Owner, "#B3");
1777                         form.Dispose ();
1778                         main.Dispose ();
1779                 }
1780
1781                 [Test] // bug #80604
1782                 public void VisibleOnLoad ()
1783                 {
1784                         MockForm form = new MockForm ();
1785                         form.CloseOnLoad = true;
1786                         Application.Run (form);
1787                         Assert.IsTrue (form.VisibleOnLoad, "#1");
1788                         form.Dispose ();
1789
1790                         form = new MockForm ();
1791                         form.ShowInTaskbar = false;
1792                         form.Show ();
1793                         Assert.IsTrue (form.VisibleOnLoad, "#2");
1794                         form.Dispose ();
1795                 }
1796
1797                 [Test] // bug #80052
1798                 [Category ("NotWorking")]
1799                 public void Location ()
1800                 {
1801                         // 
1802                         // CenterParent
1803                         // 
1804
1805                         Form formA = new Form ();
1806                         formA.ShowInTaskbar = false;
1807                         formA.StartPosition = FormStartPosition.CenterParent;
1808                         formA.Location = new Point (151, 251);
1809                         formA.Show ();
1810
1811                         Assert.AreEqual (FormStartPosition.CenterParent, formA.StartPosition, "#A1");
1812                         Assert.IsFalse (formA.Location.X == 151, "#A2");
1813                         Assert.IsFalse (formA.Location.Y == 251, "#A3");
1814
1815                         formA.Location = new Point (311, 221);
1816
1817                         Assert.AreEqual (FormStartPosition.CenterParent, formA.StartPosition, "#A4");
1818                         Assert.AreEqual (311, formA.Location.X, "#A5");
1819                         Assert.AreEqual (221, formA.Location.Y, "#A6");
1820
1821                         formA.Dispose ();
1822
1823                         // 
1824                         // CenterScreen
1825                         // 
1826
1827                         Form formB = new Form ();
1828                         formB.ShowInTaskbar = false;
1829                         formB.StartPosition = FormStartPosition.CenterScreen;
1830                         formB.Location = new Point (151, 251);
1831                         formB.Show ();
1832
1833                         Assert.AreEqual (FormStartPosition.CenterScreen, formB.StartPosition, "#B1");
1834                         Assert.IsFalse (formB.Location.X == 151, "#B2");
1835                         Assert.IsFalse (formB.Location.Y == 251, "#B3");
1836
1837                         formB.Location = new Point (311, 221);
1838
1839                         Assert.AreEqual (FormStartPosition.CenterScreen, formB.StartPosition, "#B4");
1840                         Assert.AreEqual (311, formB.Location.X, "#B5");
1841                         Assert.AreEqual (221, formB.Location.Y, "#B6");
1842
1843                         formB.Dispose ();
1844
1845                         // 
1846                         // Manual
1847                         // 
1848
1849                         Form formC = new Form ();
1850                         formC.ShowInTaskbar = false;
1851                         formC.StartPosition = FormStartPosition.Manual;
1852                         formC.Location = new Point (151, 251);
1853                         formC.Show ();
1854
1855                         Assert.AreEqual (FormStartPosition.Manual, formC.StartPosition, "#C1");
1856                         Assert.AreEqual (151, formC.Location.X, "#C2");
1857                         Assert.AreEqual (251, formC.Location.Y, "#C3");
1858
1859                         formC.Location = new Point (311, 221);
1860
1861                         Assert.AreEqual (FormStartPosition.Manual, formC.StartPosition, "#C4");
1862                         Assert.AreEqual (311, formC.Location.X, "#C5");
1863                         Assert.AreEqual (221, formC.Location.Y, "#C6");
1864
1865                         formC.Dispose ();
1866
1867                         // 
1868                         // WindowsDefaultBounds
1869                         // 
1870
1871                         Form formD = new Form ();
1872                         formD.ShowInTaskbar = false;
1873                         formD.StartPosition = FormStartPosition.WindowsDefaultBounds;
1874                         formD.Location = new Point (151, 251);
1875                         formD.Show ();
1876
1877                         Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, formD.StartPosition, "#D1");
1878                         Assert.IsFalse (formD.Location.X == 151, "#D2");
1879                         Assert.IsFalse (formD.Location.Y == 251, "#D3");
1880
1881                         formD.Location = new Point (311, 221);
1882
1883                         Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, formD.StartPosition, "#D4");
1884                         Assert.AreEqual (311, formD.Location.X, "#D5");
1885                         Assert.AreEqual (221, formD.Location.Y, "#D6");
1886
1887                         formD.Dispose ();
1888
1889                         // 
1890                         // WindowsDefaultLocation
1891                         // 
1892
1893                         Form formE = new Form ();
1894                         formE.ShowInTaskbar = false;
1895                         formE.Location = new Point (151, 251);
1896                         formE.Show ();
1897
1898                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, formE.StartPosition, "#E1");
1899                         Assert.IsFalse (formE.Location.X == 151, "#E2");
1900                         Assert.IsFalse (formE.Location.Y == 251, "#E3");
1901
1902                         formE.Location = new Point (311, 221);
1903
1904                         Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, formE.StartPosition, "#E4");
1905                         Assert.AreEqual (311, formE.Location.X, "#E5");
1906                         Assert.AreEqual (221, formE.Location.Y, "#E6");
1907
1908                         formE.Dispose ();
1909                 }
1910
1911                 [Test]
1912                 public void Opacity ()
1913                 {
1914                         Form frm;
1915                         using (frm = new Form ()) {
1916                                 Assert.AreEqual (1.0f, frm.Opacity, "#01-opacity");
1917                                 frm.Opacity = 0.50;
1918                                 Assert.AreEqual (0.50f, frm.Opacity, "#02-opacity");
1919                                 frm.Opacity = -0.1f;
1920                                 Assert.AreEqual (0, frm.Opacity, "#03-opacity");
1921                                 frm.Opacity = 1.1f;
1922                                 Assert.AreEqual (1, frm.Opacity, "#04-opacity");
1923                         }
1924                 }
1925
1926                 [Test]
1927                 public void DisposeOwnerTest ()
1928                 {
1929                         Form f1 = new Form ();
1930                         Form f2 = new Form ();
1931
1932                         f2.Owner = f1;
1933
1934                         f1.Dispose ();
1935
1936                         Assert.IsNull (f2.Owner, "1");
1937                         Assert.AreEqual (0, f1.OwnedForms.Length, "2");
1938                 }
1939
1940                 [Test]
1941                 [ExpectedException (typeof (ObjectDisposedException))]
1942                 public void AccessDisposedForm ()
1943                 {
1944                         Form myform = new Form ();
1945                         myform.ShowInTaskbar = false;
1946
1947                         myform.Show ();
1948                         myform.Close (); // this should result in the form being disposed
1949                         myform.Show (); // and this line should result in the ODE being thrown
1950                 }
1951
1952                 class MyForm : Form
1953                 {
1954                         public void DoDestroyHandle ()
1955                         {
1956                                 DestroyHandle();
1957                         }
1958                         public void DoRecreateHandle ()
1959                         {
1960                                 RecreateHandle();
1961                         }
1962                 }
1963
1964                 int handle_destroyed_count;
1965                 void handle_destroyed (object sender, EventArgs e)
1966                 {
1967                         handle_destroyed_count++;
1968                 }
1969
1970                 [Test]
1971                 public void DestroyHandleTest ()
1972                 {
1973                         handle_destroyed_count = 0;
1974
1975                         MyForm f1 = new MyForm ();
1976                         f1.HandleDestroyed += new EventHandler (handle_destroyed);
1977                         f1.Show ();
1978                         f1.DoDestroyHandle ();
1979                         Assert.AreEqual (1, handle_destroyed_count, "1");
1980
1981                         MyForm f2 = new MyForm ();
1982                         f2.HandleDestroyed += new EventHandler (handle_destroyed);
1983                         f2.Show ();
1984                         f2.DoRecreateHandle ();
1985                         Assert.AreEqual (2, handle_destroyed_count, "2");
1986                         
1987                         f1.Dispose ();
1988                         f2.Dispose ();
1989                 }
1990
1991                 [Test]
1992                 public void FormClose ()
1993                 {
1994                         Form myform = new Form ();
1995                         myform.ShowInTaskbar = false;
1996
1997                         Assert.IsFalse (myform.Visible, "A1");
1998                         Assert.IsFalse (myform.IsDisposed, "A2");
1999
2000                         myform.Close ();
2001
2002                         Assert.IsFalse (myform.Visible, "A3");
2003                         Assert.IsFalse (myform.IsDisposed, "A4");
2004
2005                         myform.Show ();
2006
2007                         Assert.IsTrue (myform.Visible, "A5");
2008                         Assert.IsFalse (myform.IsDisposed, "A6");
2009
2010                         myform.Close ();
2011
2012                         Assert.IsFalse (myform.Visible, "A7");
2013                         Assert.IsTrue (myform.IsDisposed, "A8");
2014                 }
2015
2016                 [Test]
2017                 public void FormClose2 ()
2018                 {
2019                         WMCloseWatcher f = new WMCloseWatcher ();
2020                         f.ShowInTaskbar = false;
2021
2022                         f.close_count = 0;
2023                         Assert.IsFalse (f.Visible, "A1");
2024                         f.Close ();
2025                         Assert.AreEqual (0, f.close_count, "A2");
2026
2027
2028                         f.Show ();
2029                         f.Close ();
2030                         Assert.AreEqual (1, f.close_count, "A3");
2031                 }
2032
2033                 class WMCloseWatcher : Form {
2034                         public int close_count;
2035
2036                         protected override void WndProc (ref Message msg) {
2037                                 if (msg.Msg == 0x0010 /* WM_CLOSE */) {
2038                                         close_count ++;
2039                                 }
2040
2041                                 base.WndProc (ref msg);
2042                         }
2043                 }
2044
2045                 class SwallowOnActivated : Form {
2046                         protected override void OnActivated (EventArgs e)
2047                         {
2048                                 // do nothing
2049                         }
2050
2051                         protected override void OnCreateControl () {
2052                                 base.OnCreateControl ();
2053                         }
2054                 }
2055
2056                 class EnterTest : Button {
2057                         protected override void OnEnter (EventArgs e)
2058                         {
2059                                 on_enter = true;
2060                                 base.OnEnter (e);
2061                         }
2062
2063                         public bool on_enter;
2064                 }
2065
2066                 [Test]
2067                 public void OnActivateEventHandlingTest1 ()
2068                 {
2069                         if (TestHelper.RunningOnUnix) {
2070                                 Assert.Ignore ("Relies on form.Show() synchronously generating WM_ACTIVATE");
2071                         }
2072
2073                         SwallowOnActivated f = new SwallowOnActivated ();
2074
2075                         f.ShowInTaskbar = false;
2076
2077                         EnterTest c = new EnterTest ();
2078                         f.Controls.Add (c);
2079
2080                         f.Show ();
2081
2082                         Assert.IsTrue (c.on_enter, "1");
2083
2084                         f.Dispose ();
2085                 }
2086                 
2087 #if NET_2_0
2088                 [Test]
2089                 public void FormClosingEvents ()
2090                 {
2091                         // Standard Close
2092                         Form f = new Form ();
2093                         string events = string.Empty;
2094
2095                         f.Closing += new CancelEventHandler (delegate (Object obj, CancelEventArgs e) { events += ("Closing;"); });
2096                         f.FormClosing += new FormClosingEventHandler (delegate (Object obj, FormClosingEventArgs e) { events += string.Format ("FormClosing [Reason:{0} - Cancel:{1}]", e.CloseReason, e.Cancel); });
2097         
2098                         f.Show ();
2099                         f.Close ();
2100                         
2101                         Assert.AreEqual ("Closing;FormClosing [Reason:UserClosing - Cancel:False]", events, "A1");                      
2102                 }
2103
2104                 [Test]
2105                 public void FormClosingEventsCancel ()
2106                 {
2107                         // Shows that setting Cancel in Closing flows through to FormClosing
2108                         Form f = new Form ();
2109                         string events = string.Empty;
2110
2111                         f.Closing += new CancelEventHandler (delegate (Object obj, CancelEventArgs e) { events += ("Closing;"); e.Cancel = true; });
2112                         f.FormClosing += new FormClosingEventHandler (delegate (Object obj, FormClosingEventArgs e) { events += string.Format("FormClosing [Reason:{0} - Cancel:{1}]", e.CloseReason, e.Cancel); e.Cancel = false; });
2113
2114                         f.Show ();
2115                         f.Close ();
2116
2117                         Assert.AreEqual ("Closing;FormClosing [Reason:UserClosing - Cancel:True]", events, "A1");
2118                 }
2119
2120                 [Test]
2121                 public void FormClosedEvents ()
2122                 {
2123                         // Standard Closed
2124                         Form f = new Form ();
2125                         string events = string.Empty;
2126
2127                         f.Closed += new EventHandler (delegate (Object obj, EventArgs e) { events += ("Closed;"); });
2128                         f.FormClosed += new FormClosedEventHandler (delegate (Object obj, FormClosedEventArgs e) { events += string.Format ("FormClosed [Reason:{0}]", e.CloseReason); });
2129
2130                         f.Show ();
2131                         f.Close ();
2132
2133                         Assert.AreEqual ("Closed;FormClosed [Reason:UserClosing]", events, "A1");
2134                 }
2135
2136                 [Test]
2137                 public void ShowWithOwner ()
2138                 {
2139                         Form f = new Form ();
2140                         Button b = new Button ();
2141                         f.Controls.Add (b);
2142
2143                         Form f2 = new Form ();
2144
2145                         f2.Show (f);
2146
2147                         Assert.AreSame (f, f2.Owner, "A1");
2148                         f2.Close ();
2149
2150                         f2 = new Form ();
2151
2152                         f2.Show (b);
2153                         Assert.AreSame (f, f2.Owner, "A2");
2154                         f2.Close ();
2155                         
2156                         Button b2 = new Button ();
2157                         f2 = new Form ();
2158
2159                         f2.Show (b2);
2160                         Assert.AreEqual (null, f2.Owner, "A3");
2161                         f2.Close ();
2162
2163                         f2 = new Form ();
2164                         f2.Show (null);
2165                         Assert.AreEqual (null, f2.Owner, "A4");
2166                         f2.Close ();
2167                         
2168                         f.Dispose ();
2169                 }
2170
2171                 [Test]
2172                 [ExpectedException (typeof (InvalidOperationException))]
2173                 public void ShowWithOwnerIOE ()
2174                 {
2175                         using (Form f = new Form ()) {
2176                                 f.Show (f);
2177                         }
2178                 }
2179                 
2180                 [Test]  // Bug #79959, #80574, #80791
2181                 [Category ("NotWorking")]
2182                 public void BehaviorResizeOnBorderStyleChanged ()
2183                 {
2184                         // Marked NotWorking because the ClientSize is dependent on the WM.
2185                         // The values below match XP Luna to make sure our behavior is the same.
2186                         Form f = new Form ();
2187                         f.ShowInTaskbar = false;
2188                         f.Show ();
2189
2190                         Assert.AreEqual (true, f.IsHandleCreated, "A0");
2191
2192                         Assert.AreEqual (new Size (300, 300), f.Size, "A1");
2193                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A2");
2194
2195                         f.FormBorderStyle = FormBorderStyle.Fixed3D;
2196                         Assert.AreEqual (new Size (302, 302), f.Size, "A3");
2197                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4");
2198
2199                         f.FormBorderStyle = FormBorderStyle.FixedDialog;
2200                         Assert.AreEqual (new Size (298, 298), f.Size, "A5");
2201                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A6");
2202
2203                         f.FormBorderStyle = FormBorderStyle.FixedSingle;
2204                         Assert.AreEqual (new Size (298, 298), f.Size, "A7");
2205                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A8");
2206
2207                         f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
2208                         Assert.AreEqual (new Size (298, 290), f.Size, "A9");
2209                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A0");
2210
2211                         f.FormBorderStyle = FormBorderStyle.None;
2212                         Assert.AreEqual (new Size (292, 266), f.Size, "A11");
2213                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A12");
2214
2215                         f.FormBorderStyle = FormBorderStyle.SizableToolWindow;
2216                         Assert.AreEqual (new Size (300, 292), f.Size, "A13");
2217                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A14");
2218
2219                         f.FormBorderStyle = FormBorderStyle.Sizable;
2220                         Assert.AreEqual (new Size (300, 300), f.Size, "A15");
2221                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A16");
2222                         
2223                         f.Close ();
2224                 }
2225
2226                 [Test]  // Bug #80574, #80791
2227                 [Category ("NotWorking")]
2228                 public void BehaviorResizeOnBorderStyleChangedNotVisible ()
2229                 {
2230                         // Marked NotWorking because the ClientSize is dependent on the WM.
2231                         // The values below match XP Luna to make sure our behavior is the same.
2232                         Form f = new Form ();
2233                         f.ShowInTaskbar = false;
2234
2235                         Assert.AreEqual (false, f.IsHandleCreated, "A0");
2236                         
2237                         Assert.AreEqual (new Size (300, 300), f.Size, "A1");
2238                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A2");
2239
2240                         f.FormBorderStyle = FormBorderStyle.Fixed3D;
2241                         Assert.AreEqual (new Size (300, 300), f.Size, "A3");
2242                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4");
2243
2244                         f.FormBorderStyle = FormBorderStyle.FixedDialog;
2245                         Assert.AreEqual (new Size (300, 300), f.Size, "A5");
2246                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A6");
2247
2248                         f.FormBorderStyle = FormBorderStyle.FixedSingle;
2249                         Assert.AreEqual (new Size (300, 300), f.Size, "A7");
2250                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A8");
2251
2252                         f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
2253                         Assert.AreEqual (new Size (300, 300), f.Size, "A9");
2254                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A0");
2255
2256                         f.FormBorderStyle = FormBorderStyle.None;
2257                         Assert.AreEqual (new Size (300, 300), f.Size, "A11");
2258                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A12");
2259
2260                         f.FormBorderStyle = FormBorderStyle.SizableToolWindow;
2261                         Assert.AreEqual (new Size (300, 300), f.Size, "A13");
2262                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A14");
2263
2264                         f.FormBorderStyle = FormBorderStyle.Sizable;
2265                         Assert.AreEqual (new Size (300, 300), f.Size, "A15");
2266                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A16");
2267                 }
2268
2269                 [Test]  // Bug #80574, #80791
2270                 [Category ("NotWorking")]
2271                 public void MoreBehaviorResizeOnBorderStyleChangedNotVisible ()
2272                 {
2273                         // Marked NotWorking because the ClientSize is dependent on the WM.
2274                         // The values below match XP Luna to make sure our behavior is the same.
2275                         Form f = new Form ();
2276                         f.ShowInTaskbar = false;
2277
2278                         f.Show ();
2279                         f.Hide ();
2280
2281                         Assert.AreEqual (true, f.IsHandleCreated, "A0");
2282
2283                         f.FormBorderStyle = FormBorderStyle.Sizable;
2284                         Assert.AreEqual (new Size (300, 300), f.Size, "A1");
2285                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A2");
2286                         f.FormBorderStyle = FormBorderStyle.None;
2287                         Assert.AreEqual (new Size (292, 266), f.Size, "A3");
2288                         Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4");
2289                 }
2290 #endif
2291                 
2292                 [Test]  // Bug #81582
2293                 [Category ("NotWorking")]
2294                 public void GotFocusWithoutCallingOnLoadBase ()
2295                 {
2296                         NoOnLoadBaseForm f = new NoOnLoadBaseForm ();
2297                         f.Show ();
2298                         Assert.AreEqual (true, f.got_focus_called, "H1");
2299                         f.Dispose ();
2300                 }
2301
2302                 private class NoOnLoadBaseForm : Form
2303                 {
2304                         public bool got_focus_called = false;
2305
2306                         public NoOnLoadBaseForm ()
2307                         {
2308                                 TreeView tv = new TreeView ();
2309                                 tv.GotFocus += new EventHandler (tv_GotFocus);
2310                                 Controls.Add (tv);
2311                         }
2312
2313                         void tv_GotFocus (object sender, EventArgs e)
2314                         {
2315                                 got_focus_called = true;
2316                         }
2317
2318                         protected override void OnLoad (EventArgs e)
2319                         {
2320                         }
2321                 }
2322
2323                 [Test] // bug #339641
2324                 public void ChildFocused ()
2325                 {
2326                         if (TestHelper.RunningOnUnix) {
2327                                 Assert.Ignore ("Relies on form.Show() synchronously generating WM_ACTIVATE");
2328                         }
2329                         using (Form f = new TimeBombedForm ()) {
2330                                 TreeView tv = new TreeView ();
2331                                 EventLogger log = new EventLogger (tv);
2332                                 tv.GotFocus += new EventHandler (tv_GotFocus);
2333                                 f.Activated += new EventHandler (f_Activated);
2334                                 f.Controls.Add (tv);
2335                                 f.Show ();
2336                                 Assert.IsTrue (log.EventRaised ("GotFocus"), "#01");
2337                         }
2338                 }
2339
2340                 void f_Activated (object sender, EventArgs e)
2341                 {
2342                         //Console.WriteLine ("         ACTIVATED");
2343                         //Console.WriteLine (Environment.StackTrace);
2344                 }
2345
2346                 void tv_GotFocus (object sender, EventArgs e)
2347                 {
2348                         //Console.WriteLine (Environment.StackTrace);
2349                 }
2350
2351                 [Test]  // bug #80773
2352                 public void DontSetOwnerOnShowDialogException ()
2353                 {
2354                         Form f = new Form ();
2355                         f.ShowInTaskbar = false;
2356                         
2357                         try { f.ShowDialog (f); }
2358                         catch { }
2359                         
2360                         Assert.AreEqual (null, f.Owner, "H1");
2361
2362                         f.Dispose ();
2363                 }
2364
2365                 [Test]
2366                 public void MinimumWindowSize ()
2367                 {
2368                         Form f = new Form ();
2369                         f.ShowInTaskbar = false;
2370                         f.Show ();
2371                         
2372                         f.Size = new Size (0, 0);
2373                         Assert.AreEqual (SystemInformation.MinimumWindowSize, f.Size);
2374
2375                         f.Dispose ();
2376                 }
2377
2378                 [Test]
2379                 public void Bug82470 ()
2380                 {
2381                         Form f = new Form ();
2382                         f.Load += new EventHandler (Form_LoadAndHide);
2383                         f.Show ();
2384                         
2385                         Assert.AreEqual (true, f.Visible, "A1");
2386                         
2387                         f.Dispose ();
2388                 }
2389
2390                 private void Form_LoadAndHide (object sender, EventArgs e)
2391                 {
2392                         ((Form)sender).Visible = false;
2393                 }
2394                 
2395 #if NET_2_0
2396                 [Test]
2397                 public void AutoSizeGrowOnly ()
2398                 {
2399                         Form f = new Form ();
2400                         f.ShowInTaskbar = false;
2401                         f.AutoSize = true;
2402
2403                         Button b = new Button ();
2404                         b.Size = new Size (200, 200);
2405                         b.Location = new Point (200, 200);
2406                         f.Controls.Add (b);
2407
2408                         f.Show ();
2409
2410                         Assert.AreEqual (new Size (403, 403), f.ClientSize, "A1");
2411                         
2412                         f.Controls.Remove (b);
2413                         Assert.AreEqual (new Size (403, 403), f.ClientSize, "A2");
2414                 
2415                         f.Dispose ();
2416                 }
2417
2418                 [Test]
2419                 public void AutoSizeReset ()
2420                 {
2421                         Form f = new Form ();
2422                         f.ShowInTaskbar = false;
2423
2424                         Button b = new Button ();
2425                         b.Size = new Size (200, 200);
2426                         b.Location = new Point (200, 200);
2427                         f.Controls.Add (b);
2428
2429                         f.Show ();
2430
2431                         Size start_size = f.ClientSize;
2432
2433                         f.AutoSize = true;
2434                         Assert.AreEqual (new Size (403, 403), f.ClientSize, "A1");
2435
2436                         f.AutoSize = false;
2437                         Assert.AreEqual (start_size, f.ClientSize, "A2");
2438                         f.Close ();
2439                 }
2440
2441                 [Test]
2442                 public void AutoSizeGrowAndShrink ()
2443                 {
2444                         Form f = new Form ();
2445                         f.ShowInTaskbar = false;
2446                         f.AutoSize = true;
2447                         f.AutoSizeMode = AutoSizeMode.GrowAndShrink;
2448
2449                         f.Show ();
2450
2451                         // Make sure form shrunk
2452                         Assert.IsTrue (f.ClientSize.Width < 150, "A1");
2453                         Assert.IsTrue (f.ClientSize.Height < 150, "A1-2");
2454
2455                         Button b = new Button ();
2456                         b.Size = new Size (200, 200);
2457                         b.Location = new Point (0, 0);
2458                         f.Controls.Add (b);
2459
2460                         Assert.AreEqual (new Size (203, 203), f.ClientSize, "A2");
2461                         f.Dispose ();
2462                 }
2463
2464                 [Test]
2465                 public void GetScaledBoundsTest ()
2466                 {
2467                         if (TestHelper.RunningOnUnix)
2468                                 Assert.Ignore ("Depends on WM decoration sizes, values correspond to windows");
2469
2470                         ScaleForm c = new ScaleForm ();
2471
2472                         Rectangle r = new Rectangle (100, 200, 300, 400);
2473
2474                         Assert.AreEqual (new Rectangle (100, 200, 584, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A1");
2475                         Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A2");
2476                         Assert.AreEqual (new Rectangle (100, 200, 584, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A3");
2477                         Assert.AreEqual (new Rectangle (100, 200, 300, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A4");
2478                         Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A5");
2479                         Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A6");
2480
2481                         Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (1f, 1f), BoundsSpecified.All), "A6-2");
2482                         Assert.AreEqual (new Rectangle (100, 200, 584, 764), c.PublicGetScaledBounds (r, new SizeF (2f, 2f), BoundsSpecified.All), "A7");
2483                         Assert.AreEqual (new Rectangle (100, 200, 868, 1128), c.PublicGetScaledBounds (r, new SizeF (3f, 3f), BoundsSpecified.All), "A8");
2484                         Assert.AreEqual (new Rectangle (100, 200, 1152, 1492), c.PublicGetScaledBounds (r, new SizeF (4f, 4f), BoundsSpecified.All), "A9");
2485                         Assert.AreEqual (new Rectangle (100, 200, 158, 218), c.PublicGetScaledBounds (r, new SizeF (.5f, .5f), BoundsSpecified.All), "A10");
2486                 }
2487
2488                 [Test]
2489                 public void MethodScaleControl ()
2490                 {
2491                         if (TestHelper.RunningOnUnix)
2492                                 Assert.Ignore ("Depends on WM decoration sizes, values correspond to windows");
2493                         
2494                         ScaleForm f = new ScaleForm ();
2495                         f.Location = new Point (5, 10);
2496
2497                         Assert.AreEqual (new Rectangle (5, 10, 300, 300), f.Bounds, "A1");
2498
2499                         f.PublicScaleControl (new SizeF (2.0f, 2.0f), BoundsSpecified.All);
2500                         Assert.AreEqual (new Rectangle (5, 10, 584, 564), f.Bounds, "A2");
2501
2502                         f.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Location);
2503                         Assert.AreEqual (new Rectangle (5, 10, 584, 564), f.Bounds, "A3");
2504
2505                         f.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Size);
2506                         Assert.AreEqual (new Rectangle (5, 10, 300, 300), f.Bounds, "A4");
2507
2508                         f.PublicScaleControl (new SizeF (2.5f, 2.5f), BoundsSpecified.Size);
2509                         Assert.AreEqual (new Rectangle (5, 10, 726, 696), f.Bounds, "A5");
2510
2511                         f.PublicScaleControl (new SizeF (.3f, .3f), BoundsSpecified.Size);
2512                         Assert.AreEqual (new Rectangle (5, 10, 229, 234), f.Bounds, "A6");
2513
2514                         f.Dispose ();
2515                 }
2516
2517                 private class ScaleForm : Form
2518                 {
2519                         public Rectangle PublicGetScaledBounds (Rectangle bounds, SizeF factor, BoundsSpecified specified)
2520                         {
2521                                 return base.GetScaledBounds (bounds, factor, specified);
2522                         }
2523
2524                         public void PublicScaleControl (SizeF factor, BoundsSpecified specified)
2525                         {
2526                                 base.ScaleControl (factor, specified);
2527                         }
2528                 }
2529 #endif
2530                 [Test]
2531                 public void Bug325436 ()
2532                 {
2533                         Form f = new Form ();
2534                         f.ShowInTaskbar = false;
2535                         f.ClientSize = new Size (320, 40);
2536                         f.ControlBox = false;
2537                         f.FormBorderStyle = FormBorderStyle.None;
2538                         f.MaximizeBox = false;
2539                         f.MinimizeBox = false;
2540                         
2541                         f.Show ();
2542                         Assert.AreEqual (new Size (320, 40), f.ClientSize, "A1");
2543                         f.Dispose ();
2544
2545                         f = new Form ();
2546                         f.ShowInTaskbar = false;
2547                         f.ControlBox = false;
2548                         f.FormBorderStyle = FormBorderStyle.None;
2549                         f.MaximizeBox = false;
2550                         f.MinimizeBox = false;
2551                         f.ClientSize = new Size(320, 40);
2552                         
2553                         f.Show ();
2554                         Assert.AreEqual (new Size (320, 40), f.ClientSize, "A2");
2555                         f.Dispose ();
2556                 }
2557
2558 #if NET_2_0
2559                 #region PreferredSize
2560                 [Test]
2561                 public void PreferredSize ()
2562                 {
2563                         PreferredSizeForm form = new PreferredSizeForm ();
2564                         form.AutoSize = true;
2565                         Control control = new Control ();
2566                         form.Controls.Add (control);
2567                         control.Size = new Size (500, 500);
2568                         form.Test ();
2569                         form.Controls.Clear ();
2570                         form.Test2 ();
2571
2572                 }
2573
2574                 private class PreferredSizeForm : Form
2575                 {
2576                         public void Test ()
2577                         {
2578                                 Assert.AreEqual (SizeFromClientSize (new Size (503, 503)), PreferredSize, "1");
2579                         }
2580
2581                         public void Test2 ()
2582                         {
2583                                 Assert.AreEqual (SizeFromClientSize (new Size (0, 0)), PreferredSize, "1");
2584                         }
2585                 }
2586                 #endregion
2587 #endif
2588                 private class MockForm : Form
2589                 {
2590                         public bool CloseOnLoad {
2591                                 get { return _closeOnLoad; }
2592                                 set { _closeOnLoad = value; }
2593                         }
2594
2595                         public bool VisibleOnLoad {
2596                                 get { return _visibleOnLoad; }
2597                         }
2598
2599                         protected override void OnLoad(EventArgs e) {
2600                                 base.OnLoad(e);
2601                                 _visibleOnLoad = Visible;
2602                                 if (CloseOnLoad)
2603                                         Close ();
2604                         }
2605
2606                         private bool _closeOnLoad;
2607                         private bool _visibleOnLoad;
2608                 }
2609
2610                 private class MockButton : Button
2611                 {
2612                         public MockButton (bool notify)
2613                         {
2614                                 _notify = notify;
2615                         }
2616
2617                         public bool Notify {
2618                                 get { return _notify; }
2619                                 set { _notify = value; }
2620                         }
2621
2622                         public bool IsDefaultButton
2623                         {
2624                                 get { return base.IsDefault; }
2625                                 set { base.IsDefault = value; }
2626                         }
2627
2628                         public override void NotifyDefault (bool value)
2629                         {
2630                                 if (Notify)
2631                                         base.NotifyDefault (value);
2632                         }
2633
2634                         private bool _notify;
2635                 }
2636
2637                 private class ButtonControl : IButtonControl
2638                 {
2639                         public DialogResult DialogResult {
2640                                 get { return _dialogResult; }
2641                                 set { _dialogResult = value; }
2642                         }
2643
2644                         public bool IsDefaultButton {
2645                                 get { return _isDefault; }
2646                         }
2647
2648                         public void NotifyDefault (bool value)
2649                         {
2650                                 _isDefault = value;
2651                         }
2652
2653                         public void PerformClick ()
2654                         {
2655                         }
2656
2657                         private bool _isDefault;
2658                         private DialogResult _dialogResult = DialogResult.None;
2659                 }
2660                 
2661 #if NET_2_0
2662                 [Test]
2663                 public void RestoreBounds ()
2664                 {
2665                         Form f = new Form ();
2666                         f.Show ();
2667                         
2668                         Assert.AreEqual (new Size (300, 300), f.RestoreBounds.Size, "A1");
2669                         
2670                         // Move the form
2671                         f.Location = new Point (0, 0);
2672                         Assert.AreEqual (new Rectangle (0, 0, 300, 300), f.RestoreBounds, "A2");
2673                         
2674                         // Resize the form
2675                         f.Size = new Size (250, 250);
2676                         Assert.AreEqual (new Rectangle (0, 0, 250, 250), f.RestoreBounds, "A3");
2677                         
2678                         // Minimize the form
2679                         f.WindowState = FormWindowState.Minimized;
2680                         Assert.AreEqual (new Rectangle (0, 0, 250, 250), f.RestoreBounds, "A4");
2681
2682                         // Move the form (while minimized)
2683                         f.Location = new Point (10, 10);
2684                         Assert.AreEqual (new Rectangle (10, 10, 250, 250), f.RestoreBounds, "A5");
2685
2686                         // Resize the form (while minimized)
2687                         f.Size = new Size (275, 275);
2688                         Assert.AreEqual (new Rectangle (10, 10, 275, 275), f.RestoreBounds, "A6");
2689                         
2690                         // Maximize the form
2691                         f.WindowState = FormWindowState.Maximized;
2692                         Assert.AreEqual (new Rectangle (10, 10, 275, 275), f.RestoreBounds, "A7");
2693
2694                         // Move the form (while maximized)
2695                         f.Location = new Point (20, 20);
2696                         Assert.AreEqual (new Rectangle (20, 20, 275, 275), f.RestoreBounds, "A8");
2697
2698                         // Resize the form (while maximized)
2699                         f.Size = new Size (285, 285);
2700                         Assert.AreEqual (new Rectangle (20, 20, 285, 285), f.RestoreBounds, "A9");
2701                         
2702                         f.Dispose ();
2703                 }
2704                 
2705                 [Test]  // Bug 353827
2706                 public void AutoScaleModeTest ()
2707                 {
2708                         Form f = new Form ();
2709                         
2710                         // AutoScale starts off true
2711                         Assert.AreEqual (true, f.AutoScale, "A1");
2712                         
2713                         // Setting AutoScaleMode turns AutoScale off
2714                         f.AutoScaleMode = AutoScaleMode.Font;
2715                         Assert.AreEqual (false, f.AutoScale, "A2");
2716                         Assert.AreEqual (AutoScaleMode.Font, f.AutoScaleMode, "A3");
2717
2718                         // Changing Font resets AutoScaleBaseSize..
2719                         f.Font = new Font ("Arial", 10);
2720                         Assert.AreEqual (RoundSizeF (Form.GetAutoScaleSize (f.Font)), f.AutoScaleBaseSize, "A4");
2721
2722                         f.Font = new Font ("Arial", 12);
2723                         Assert.AreEqual (RoundSizeF (Form.GetAutoScaleSize (f.Font)), f.AutoScaleBaseSize, "A5");
2724                         
2725                         // ..Until AutoScaleBaseSize is explicitly set
2726                         f.AutoScaleBaseSize = new Size (5, 13);
2727                         Assert.AreEqual (new Size (5, 13), f.AutoScaleBaseSize, "A6");
2728
2729                         f.Font = new Font ("Arial", 14F);
2730                         Assert.IsTrue (RoundSizeF (Form.GetAutoScaleSize (f.Font)) != f.AutoScaleBaseSize, "A5");
2731         
2732                         f.Dispose ();
2733                 }
2734                 
2735                 private Size RoundSizeF (SizeF sizef)
2736                 {
2737                         return new Size ((int)Math.Round (sizef.Width), (int)Math.Round (sizef.Height));
2738                 }
2739                 
2740                 [Test] // Bug 354669
2741                 public void AutoScaleDetails ()
2742                 {
2743                         ProtectedForm f = new ProtectedForm ();
2744                         f.Show ();
2745                         
2746                         f.SuspendLayout ();
2747                         
2748                         // First AutoScaleMode shouldn't reset AutoScaleDimensions
2749                         f.AutoScaleDimensions = new SizeF (3F, 3F);
2750                         f.AutoScaleMode = AutoScaleMode.Font;
2751                         Assert.AreEqual (new SizeF (3F, 3F), f.AutoScaleDimensions, "A1");
2752                         
2753                         // Subsequent calls will reset it to 0, 0
2754                         f.AutoScaleMode = AutoScaleMode.Dpi;
2755                         Assert.AreEqual (SizeF.Empty, f.AutoScaleDimensions, "A2");
2756
2757                         f.ResumeLayout ();
2758                         
2759                         // CurrentAutoScaleDimensions should be nonzero
2760                         Assert.IsFalse (f.CurrentAutoScaleDimensions == SizeF.Empty, "A3");
2761                         
2762                         // AutoScaleDimensions and CurrentAutoScaleDimensions should match after ResumeLayout
2763                         Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A4");
2764
2765                         // CurrentAutoScaleDimensions should match AutoScaleDimensions for AutoScaleMode.None
2766                         f.SuspendLayout ();
2767                         f.AutoScaleMode = AutoScaleMode.None;
2768                         f.AutoScaleDimensions = new SizeF (5F, 5F);
2769
2770                         Assert.AreEqual (new SizeF (5F, 5F), f.AutoScaleDimensions, "A5");
2771                         Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A6");
2772
2773                         // ResumeLayout changes nothing
2774                         f.ResumeLayout ();
2775
2776                         Assert.AreEqual (new SizeF (5F, 5F), f.AutoScaleDimensions, "A7");
2777                         Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A8");
2778
2779                         // AutoScaleFactor should be ~2,2 if PerformAutoScale hasn't run
2780                         f.ClientSize = new Size (150, 150);
2781                         f.SuspendLayout ();
2782                         f.AutoScaleMode = AutoScaleMode.Dpi;
2783                         f.AutoScaleDimensions = new SizeF (f.CurrentAutoScaleDimensions.Width / 2F, f.CurrentAutoScaleDimensions.Height / 2F);
2784                         f.ClientSize = new Size (200, 200);
2785
2786                         Assert.AreEqual (new Size (2, 2), RoundSizeF (f.GetPublicAutoScaleFactor ()), "A9");
2787
2788                         // AutoScaleFactor should be 1 after ResumeLayout
2789                         f.ResumeLayout ();
2790
2791                         Assert.AreEqual (new SizeF (1F, 1F), f.GetPublicAutoScaleFactor (), "A10");
2792                         Assert.AreEqual (new Size (400, 400), f.ClientSize, "A11");
2793                         
2794                         // PerformAutoScale happens immediately when layout not suspended
2795                         f.ClientSize = new Size (125, 125);
2796                         f.AutoScaleDimensions = new SizeF (f.CurrentAutoScaleDimensions.Width / 2F, f.CurrentAutoScaleDimensions.Height / 2F);
2797                         Assert.AreEqual (new Size (250, 250), f.ClientSize, "A12");
2798                         
2799                         f.Dispose ();
2800                 }
2801                 
2802                 private class ProtectedForm : Form
2803                 {
2804                         public SizeF GetPublicAutoScaleFactor ()
2805                         {
2806                                 return AutoScaleFactor;
2807                         }
2808                 }
2809 #endif
2810         }
2811
2812         public class TimeBombedForm : Form
2813         {
2814                 public Timer timer;
2815                 public bool CloseOnPaint;
2816                 public string Reason;
2817                 public TimeBombedForm ()
2818                 {
2819                         timer = new Timer ();
2820                         timer.Interval = 500;
2821                         timer.Tick += new EventHandler (timer_Tick);
2822                         timer.Start ();
2823                 }
2824
2825                 void timer_Tick (object sender, EventArgs e)
2826                 {
2827                         Reason = "Bombed";
2828                         Close ();
2829                 }
2830
2831                 protected override void OnPaint (PaintEventArgs pevent)
2832                 {
2833                         base.OnPaint (pevent);
2834                         if (CloseOnPaint) {
2835                                 Reason = "OnPaint";
2836                                 Close ();
2837                         }
2838                 }
2839         }
2840 }