2 // FormTest.cs: Test cases for Form.
5 // Ritvik Mayank (mritvik@novell.com)
7 // (C) 2005 Novell, Inc. (http://www.novell.com)
11 using System.ComponentModel;
13 using System.Reflection;
14 using System.Windows.Forms;
15 using System.Collections;
17 using NUnit.Framework;
19 using CategoryAttribute = NUnit.Framework.CategoryAttribute;
21 namespace MonoTests.System.Windows.Forms
27 public void AcceptButton ()
29 Form form = new Form ();
30 Assert.IsNull (form.AcceptButton, "#A");
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");
39 form.AcceptButton = null;
40 Assert.IsNull (form.AcceptButton, "#C1");
41 Assert.IsFalse (buttonA.IsDefaultButton, "#C2");
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");
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");
62 public void bug_82358 ()
64 //Console.WriteLine ("Starting bug_82358");
72 // WinXP, default theme
80 // WinXP, Win32 theme:
89 Size size = new Size (200, 200);
92 using (Form f = new Form ()) {
93 f.FormBorderStyle = FormBorderStyle.FixedSingle;
95 d2 = f.Size.Width - f.ClientSize.Width;
96 title_bar = f.Size.Height - f.ClientSize.Height - d2;
98 using (Form f = new Form ()) {
99 f.FormBorderStyle = FormBorderStyle.Sizable;
101 sizeable_factor = f.Size.Width - f.ClientSize.Width - d2;
103 using (Form f = new Form ()) {
105 f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
107 tool_border = f.Size.Width - f.ClientSize.Width;
108 tool_bar = f.Size.Height - f.ClientSize.Height - tool_border;
110 using (Form f = new Form ()) {
111 f.FormBorderStyle = FormBorderStyle.Fixed3D;
113 d3 = f.Size.Width - f.ClientSize.Width;
116 FormBorderStyle style;
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);
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);
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");
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");
137 using (Form f = new Form ()) {
138 style = FormBorderStyle.SizableToolWindow;
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");
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");
148 using (Form f = new Form ()) {
149 style = FormBorderStyle.Fixed3D;
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");
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");
159 using (Form f = new Form ()) {
160 style = FormBorderStyle.FixedDialog;
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");
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");
171 using (Form f = new Form ()) {
172 style = FormBorderStyle.FixedSingle;
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");
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");
182 using (Form f = new Form ()) {
183 style = FormBorderStyle.None;
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");
189 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-A3");
190 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-A4");
193 using (Form f = new Form ()) {
194 style = FormBorderStyle.Sizable;
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");
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");
205 // Changing size, then FormBorderStyle.
206 using (Form f = new Form ()) {
207 style = FormBorderStyle.FixedToolWindow;
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");
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");
217 using (Form f = new Form ()) {
218 style = FormBorderStyle.SizableToolWindow;
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");
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");
228 using (Form f = new Form ()) {
229 style = FormBorderStyle.Fixed3D;
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");
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");
239 using (Form f = new Form ()) {
240 style = FormBorderStyle.FixedDialog;
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");
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");
251 using (Form f = new Form ()) {
252 style = FormBorderStyle.FixedSingle;
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");
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");
262 using (Form f = new Form ()) {
263 style = FormBorderStyle.None;
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");
269 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-B3");
270 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-B4");
273 using (Form f = new Form ()) {
274 style = FormBorderStyle.Sizable;
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");
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");
286 // Changing FormBorderStyle, then client size
287 using (Form f = new Form ()) {
288 style = FormBorderStyle.FixedToolWindow;
289 f.FormBorderStyle = style;
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");
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");
298 using (Form f = new Form ()) {
299 style = FormBorderStyle.SizableToolWindow;
300 f.FormBorderStyle = style;
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");
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");
309 using (Form f = new Form ()) {
310 style = FormBorderStyle.Fixed3D;
311 f.FormBorderStyle = style;
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");
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");
320 using (Form f = new Form ()) {
321 style = FormBorderStyle.FixedDialog;
322 f.FormBorderStyle = style;
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");
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");
332 using (Form f = new Form ()) {
333 style = FormBorderStyle.FixedSingle;
334 f.FormBorderStyle = style;
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");
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");
343 using (Form f = new Form ()) {
344 style = FormBorderStyle.None;
345 f.FormBorderStyle = style;
347 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C1");
348 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-C2");
350 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-C3");
351 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-C4");
354 using (Form f = new Form ()) {
355 style = FormBorderStyle.Sizable;
356 f.FormBorderStyle = style;
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");
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");
366 // Changing FormBorderStyle, then size
367 using (Form f = new Form ()) {
368 style = FormBorderStyle.FixedToolWindow;
369 f.FormBorderStyle = style;
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");
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");
378 using (Form f = new Form ()) {
379 style = FormBorderStyle.SizableToolWindow;
380 f.FormBorderStyle = style;
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");
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");
389 using (Form f = new Form ()) {
390 style = FormBorderStyle.Fixed3D;
391 f.FormBorderStyle = style;
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");
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");
400 using (Form f = new Form ()) {
401 style = FormBorderStyle.FixedDialog;
402 f.FormBorderStyle = style;
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");
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");
412 using (Form f = new Form ()) {
413 style = FormBorderStyle.FixedSingle;
414 f.FormBorderStyle = style;
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");
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");
423 using (Form f = new Form ()) {
424 style = FormBorderStyle.None;
425 f.FormBorderStyle = style;
427 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-D1");
428 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D2");
430 Assert.AreEqual (size.ToString (), f.ClientSize.ToString (), style.ToString () + "-D3");
431 Assert.AreEqual (size.ToString (), f.Size.ToString (), style.ToString () + "-D4");
434 using (Form f = new Form ()) {
435 style = FormBorderStyle.Sizable;
436 f.FormBorderStyle = style;
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");
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");
447 // Set clientsize, then change size, then FormBorderStyle.
448 using (Form f = new Form ()) {
449 style = FormBorderStyle.FixedToolWindow;
450 f.ClientSize = f.ClientSize;
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");
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");
462 using (Form f = new Form ()) {
463 style = FormBorderStyle.SizableToolWindow;
464 f.ClientSize = f.ClientSize;
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");
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");
474 using (Form f = new Form ()) {
475 style = FormBorderStyle.Fixed3D;
476 f.ClientSize = f.ClientSize;
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");
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");
486 using (Form f = new Form ()) {
487 style = FormBorderStyle.FixedDialog;
488 f.ClientSize = f.ClientSize;
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");
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");
499 using (Form f = new Form ()) {
500 style = FormBorderStyle.FixedSingle;
501 f.ClientSize = f.ClientSize;
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");
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");
511 using (Form f = new Form ()) {
512 style = FormBorderStyle.None;
513 f.ClientSize = f.ClientSize;
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");
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");
523 using (Form f = new Form ()) {
524 style = FormBorderStyle.Sizable;
525 f.ClientSize = f.ClientSize;
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");
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");
541 public void StartPositionClosedForm ()
543 using (Form form = new Form ()) {
544 form.StartPosition = FormStartPosition.CenterParent;
545 form.Load += new EventHandler (CenterDisposedForm_Load);
549 using (Form form = new Form ()) {
550 form.StartPosition = FormStartPosition.CenterScreen;
551 form.Load += new EventHandler (CenterDisposedForm_Load);
556 using (Form form = new Form ()) {
557 form.StartPosition = FormStartPosition.Manual;
558 form.Load += new EventHandler (CenterDisposedForm_Load);
563 using (Form form = new Form ()) {
564 form.StartPosition = FormStartPosition.WindowsDefaultBounds;
565 form.Load += new EventHandler (CenterDisposedForm_Load);
569 using (Form form = new Form ()) {
570 form.StartPosition = FormStartPosition.WindowsDefaultLocation;
571 form.Load += new EventHandler (CenterDisposedForm_Load);
578 [ExpectedException (typeof (ObjectDisposedException))]
579 public void CenterToParentDisposedForm ()
581 using (FormHandleTest.ProtectedMethodsForm form = new FormHandleTest.ProtectedMethodsForm ()) {
583 form.PublicCenterToParent ();
588 [ExpectedException (typeof (ObjectDisposedException))]
589 public void CenterToScreenDisposedForm ()
591 using (FormHandleTest.ProtectedMethodsForm form = new FormHandleTest.ProtectedMethodsForm ()) {
593 form.PublicCenterToScreen ();
598 public void SetStartPositionDisposedForm ()
600 using (FormHandleTest.ProtectedMethodsForm form = new FormHandleTest.ProtectedMethodsForm ()) {
602 form.StartPosition = FormStartPosition.WindowsDefaultLocation;
606 private void CenterDisposedForm_Load (object sender, EventArgs e)
608 ((Form) sender).Close ();
612 public void ShowDialogCloseTest ()
614 using (TimeBombedForm f = new TimeBombedForm ()) {
615 EventLogger log = new EventLogger (f);
616 f.timer.Interval = 1000;
617 f.VisibleChanged += new EventHandler (Form_VisibleChanged1);
620 Assert.AreEqual ("VisibleChanged", f.Reason, "#00");
621 Assert.AreEqual (1, log.CountEvents ("Closing"), "#01");
623 Assert.AreEqual (1, log.CountEvents ("FormClosing"), "#02");
625 Assert.AreEqual (1, log.CountEvents ("HandleDestroyed"), "#03");
627 Assert.AreEqual (0, log.CountEvents ("Closed"), "#04");
629 Assert.AreEqual (0, log.CountEvents ("FormClosed"), "#05");
631 Assert.AreEqual (0, log.CountEvents ("Disposed"), "#06");
634 using (TimeBombedForm f = new TimeBombedForm ()) {
635 EventLogger log = new EventLogger (f);
638 Assert.AreEqual ("Bombed", f.Reason, "#A0");
639 Assert.AreEqual (1, log.CountEvents ("Closing"), "#A1");
641 Assert.AreEqual (1, log.CountEvents ("FormClosing"), "#A2");
643 Assert.AreEqual (1, log.CountEvents ("HandleDestroyed"), "#A3");
645 Assert.AreEqual (1, log.CountEvents ("Closed"), "#A4");
647 Assert.AreEqual (1, log.CountEvents ("FormClosed"), "#A5");
649 Assert.AreEqual (0, log.CountEvents ("Disposed"), "#A6");
653 using (TimeBombedForm f = new TimeBombedForm ()) {
654 EventLogger log = new EventLogger (f);
655 f.VisibleChanged += new EventHandler (Form_VisibleChanged2);
658 Assert.AreEqual ("VisibleChanged", f.Reason, "#B0");
660 Assert.AreEqual (1, log.CountEvents ("Closing"), "#B1");
661 Assert.AreEqual (1, log.CountEvents ("FormClosing"), "#B2");
663 Assert.AreEqual (1, log.CountEvents ("HandleDestroyed"), "#B3");
666 Assert.AreEqual (1, log.CountEvents ("Closed"), "#B4");
667 Assert.AreEqual (1, log.CountEvents ("FormClosed"), "#B5");
669 Assert.AreEqual (0, log.CountEvents ("Disposed"), "#B6");
673 using (TimeBombedForm f = new TimeBombedForm ()) {
674 EventLogger log = new EventLogger (f);
675 f.DialogResult = DialogResult.None;
678 Assert.AreEqual ("Bombed", f.Reason, "#C0");
679 Assert.AreEqual (1, log.CountEvents ("Closing"), "#C1");
681 Assert.AreEqual (1, log.CountEvents ("FormClosing"), "#C2");
683 Assert.AreEqual (1, log.CountEvents ("HandleDestroyed"), "#C3");
685 Assert.AreEqual (1, log.CountEvents ("Closed"), "#C4");
687 Assert.AreEqual (1, log.CountEvents ("FormClosed"), "#C5");
689 Assert.AreEqual (0, log.CountEvents ("Disposed"), "#C6");
691 Assert.AreEqual (DialogResult.Cancel, f.DialogResult, "#C7");
695 void Form_VisibleChanged1 (object sender, EventArgs e)
697 TimeBombedForm f = (TimeBombedForm) sender;
698 f.Reason = "VisibleChanged";
702 void Form_VisibleChanged2 (object sender, EventArgs e)
704 TimeBombedForm f = (TimeBombedForm) sender;
705 f.Reason = "VisibleChanged";
707 f.DialogResult = DialogResult.OK;
708 Assert.IsFalse (f.Visible);
712 public void DialogOwnerTest ()
714 using (Form first = new Form ()) {
715 using (TimeBombedForm second = new TimeBombedForm ()) {
717 second.Load += new EventHandler (second_Load);
718 second.ShowDialog ();
723 void second_Load (object sender, EventArgs e)
725 Form second = (Form) sender;
726 Assert.IsNull (second.Owner, "#1");
730 [Category ("NotWorking")]
731 public void FormStartupPositionChangeTest ()
733 using (Form frm = new Form ())
735 frm.ShowInTaskbar = false;
736 frm.StartPosition = FormStartPosition.Manual;
737 frm.Location = new Point (0, 0);
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 ();
745 Assert.AreEqual ("{X=0,Y=0}", frm.Location.ToString (), "#01");
747 frm.StartPosition = FormStartPosition.CenterParent;
748 Assert.AreEqual ("{X=0,Y=0}", frm.Location.ToString (), "#02");
750 frm.StartPosition = FormStartPosition.CenterScreen;
751 Assert.AreEqual ("{X=0,Y=0}", frm.Location.ToString (), "#03");
753 frm.StartPosition = FormStartPosition.Manual;
754 Assert.AreEqual ("{X=0,Y=0}", frm.Location.ToString (), "#04");
756 frm.StartPosition = FormStartPosition.WindowsDefaultBounds;
757 Assert.AreEqual ("{X=0,Y=0}", frm.Location.ToString (), "#05");
759 frm.StartPosition = FormStartPosition.WindowsDefaultLocation;
760 Assert.AreEqual ("{X=0,Y=0}", frm.Location.ToString (), "#06");
765 public void FormStartupPositionTest ()
769 using (Form frm = new Form ())
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");
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");
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");
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");
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");
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");
803 using (Form frm = new Form ()) {
804 frm.Location = new Point (23, 45);
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");
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");
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");
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");
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");
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");
838 public void MdiFormStartupPositionTest ()
841 using (Form Main = new Form ()) {
842 Main.IsMdiContainer = true;
843 Main.ShowInTaskbar = false;
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");
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");
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");
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");
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");
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");
879 using (Form frm = new Form ()) {
880 frm.MdiParent = Main;
881 frm.Location = new Point (23, 45);
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");
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");
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");
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");
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");
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");
915 using (Form frm = new Form ()) {
916 frm.MdiParent = Main;
917 frm.Location = new Point (34, 56);
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");
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");
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");
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");
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");
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");
951 Main.Size = new Size (600, 600);
952 using (Form frm = new Form ()) {
953 frm.MdiParent = Main;
954 frm.Location = new Point (34, 56);
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");
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");
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");
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");
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");
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");
991 public void ParentedFormStartupPositionTest ()
994 using (Form Main = new Form ()) {
995 Main.ShowInTaskbar = false;
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");
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");
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");
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");
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");
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");
1032 using (Form frm = new Form ()) {
1033 frm.TopLevel = false;
1034 Main.Controls.Add (frm);
1035 frm.Location = new Point (23, 45);
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");
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");
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");
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");
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");
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");
1069 using (Form frm = new Form ()) {
1070 frm.TopLevel = false;
1071 Main.Controls.Add (frm);
1072 frm.Location = new Point (34, 56);
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");
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");
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");
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");
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");
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");
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);
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");
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");
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");
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");
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");
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");
1147 public void UnparentForm ()
1149 Form f1 = new Form ();
1152 Form f2 = new Form ();
1153 f2.TopLevel = false;
1155 Assert.AreSame (f1, f2.Parent, "#1");
1158 Assert.IsNull (f2.Parent, "#2");
1161 [Test] // bug #80791
1162 public void ClientSizeTest ()
1164 Form form = new Form ();
1165 Assert.IsFalse (form.ClientSize == form.Size);
1168 [Test] // bug #80574
1169 [Category ("NotWorking")]
1170 public void FormBorderStyleTest ()
1172 Form form = new Form ();
1173 Rectangle boundsBeforeBorderStyleChange = form.Bounds;
1174 Rectangle clientRectangleBeforeBorderStyleChange = form.ClientRectangle;
1175 form.FormBorderStyle = FormBorderStyle.None;
1176 Assert.AreEqual (form.Bounds, boundsBeforeBorderStyleChange, "#A1");
1177 Assert.AreEqual (form.ClientRectangle, clientRectangleBeforeBorderStyleChange, "#A2");
1179 form.Visible = true;
1180 form.FormBorderStyle = FormBorderStyle.Sizable;
1181 boundsBeforeBorderStyleChange = form.Bounds;
1182 clientRectangleBeforeBorderStyleChange = form.ClientRectangle;
1183 form.FormBorderStyle = FormBorderStyle.None;
1184 Assert.IsFalse (form.Bounds == boundsBeforeBorderStyleChange, "#B1");
1185 Assert.AreEqual (form.ClientRectangle, clientRectangleBeforeBorderStyleChange, "#B2");
1187 form.Visible = false;
1188 form.FormBorderStyle = FormBorderStyle.Sizable;
1189 boundsBeforeBorderStyleChange = form.Bounds;
1190 clientRectangleBeforeBorderStyleChange = form.ClientRectangle;
1191 form.FormBorderStyle = FormBorderStyle.None;
1192 Assert.IsFalse (form.Bounds == boundsBeforeBorderStyleChange, "#C1");
1193 Assert.AreEqual (form.ClientRectangle, clientRectangleBeforeBorderStyleChange, "#C2");
1197 [Category ("NotWorking")]
1198 public void MaximizedParentedFormTest ()
1200 using (Form Main = new Form ()) {
1201 Form Child = new Form ();
1202 Child.TopLevel = false;
1203 Main.Controls.Add (Child);
1204 Main.ShowInTaskbar = false;
1207 Child.WindowState = FormWindowState.Maximized;
1208 Child.Visible = true;
1209 // The exact negative value depends on the border with, but it should always be < 0.
1210 Assert.IsTrue (Child.Location.X < 0 && Child.Location.Y < 0, "#A1");
1214 [Category ("NotWorking")]
1215 public void ParentedFormEventTest ()
1218 using (Form Main = new Form ()) {
1219 Form Child = new Form ();
1220 Child.TopLevel = false;
1221 Child.Visible = true;
1222 Main.ShowInTaskbar = false;
1225 EventLogger log = new EventLogger (Child);
1226 Assert.AreEqual (true, Child.Visible, "#A0");
1227 Main.Controls.Add (Child);
1228 Assert.AreEqual (true, Child.Visible, "#B0");
1229 Assert.AreEqual ("ParentChanged;BindingContextChanged;Layout;VisibleChanged;BindingContextChanged;BindingContextChanged", log.EventsJoined (), "#B1");
1233 [NUnit.Framework.Category ("NotWorking")]
1234 public void FormCreateParamsStyleTest ()
1238 using (frm = new Form ()) {
1239 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles) TestHelper.GetCreateParams (frm).Style), "#01-Style");
1240 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles) TestHelper.GetCreateParams (frm).ExStyle), "#01-ExStyle");
1243 using (frm = new Form ()) {
1244 frm.AllowDrop = !frm.AllowDrop;
1245 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#02-Style");
1246 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#02-ExStyle");
1249 using (frm = new Form ()) {
1250 frm.AllowTransparency = !frm.AllowTransparency;
1251 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#03-Style");
1252 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_LAYERED, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#03-ExStyle");
1255 using (frm = new Form ()) {
1257 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#04-Style");
1258 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_LAYERED, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#04-ExStyle");
1261 using (frm = new Form ()) {
1262 frm.TransparencyKey = Color.Cyan;
1263 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#05-Style");
1264 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_LAYERED, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#05-ExStyle");
1267 using (frm = new Form ()) {
1268 frm.CausesValidation = !frm.CausesValidation;
1269 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#06-Style");
1270 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#06-ExStyle");
1273 using (frm = new Form ()) {
1274 frm.ControlBox = !frm.ControlBox;
1275 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_THICKFRAME | WindowStyles.WS_BORDER | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#07-Style");
1276 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#07-ExStyle");
1279 using (frm = new Form ()) {
1281 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#08-Style");
1282 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#08-ExStyle");
1285 using (frm = new Form ()) {
1286 frm.FormBorderStyle = FormBorderStyle.Fixed3D;
1287 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#10-Style");
1288 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CLIENTEDGE | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#10-ExStyle");
1291 using (frm = new Form ()) {
1292 frm.FormBorderStyle = FormBorderStyle.FixedDialog;
1293 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#11-Style");
1294 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#11-ExStyle");
1297 using (frm = new Form ()) {
1298 frm.FormBorderStyle = FormBorderStyle.FixedSingle;
1299 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#12-Style");
1300 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#12-ExStyle");
1303 using (frm = new Form ()) {
1304 frm.FormBorderStyle = FormBorderStyle.FixedToolWindow;
1305 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#13-Style");
1306 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_TOOLWINDOW | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#13-ExStyle");
1309 using (frm = new Form ()) {
1310 frm.FormBorderStyle = FormBorderStyle.None;
1311 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#14-Style");
1312 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#14-ExStyle");
1315 using (frm = new Form ()) {
1316 frm.FormBorderStyle = FormBorderStyle.Sizable;
1317 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#15-Style");
1318 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#15-ExStyle");
1321 using (frm = new Form ()) {
1322 frm.FormBorderStyle = FormBorderStyle.SizableToolWindow;
1323 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#16-Style");
1324 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_TOOLWINDOW | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#16-ExStyle");
1327 using (frm = new Form ()) {
1328 frm.HelpButton = !frm.HelpButton;
1329 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#17-Style");
1330 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#17-ExStyle");
1333 using (frm = new Form ()) {
1335 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#18-Style");
1336 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#18-ExStyle");
1339 using (frm = new Form ()) {
1340 frm.Icon = SystemIcons.Asterisk;
1341 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#19-Style");
1342 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#19-ExStyle");
1345 using (frm = new Form ()) {
1346 frm.IsMdiContainer = !frm.IsMdiContainer;
1347 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#20-Style");
1348 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#20-ExStyle");
1351 using (frm = new Form ()) {
1352 frm.MaximizeBox = !frm.MaximizeBox;
1353 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_GROUP | WindowStyles.WS_THICKFRAME | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#21-Style");
1354 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#21-ExStyle");
1357 using (frm = new Form ()) {
1358 frm.MinimizeBox = !frm.MinimizeBox;
1359 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_THICKFRAME | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#22-Style");
1360 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#22-ExStyle");
1363 using (frm = new Form ()) {
1364 frm.ShowIcon = !frm.ShowIcon;
1365 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#23-Style");
1366 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#23-ExStyle");
1369 using (frm = new Form ()) {
1370 frm.ShowInTaskbar = !frm.ShowInTaskbar;
1371 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#24-Style");
1372 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#24-ExStyle");
1376 using (frm = new Form ()) {
1377 frm.TabStop = !frm.TabStop;
1378 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#25-Style");
1379 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#25-ExStyle");
1382 using (frm = new Form ()) {
1383 frm.TopLevel = !frm.TopLevel;
1384 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_CHILD, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#26-Style");
1385 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#26-ExStyle");
1388 using (frm = new Form ()) {
1389 frm.Visible = !frm.Visible;
1390 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#27-Style");
1391 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#27-ExStyle");
1394 using (frm = new Form ()) {
1395 frm.ControlBox = false;
1397 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_THICKFRAME | WindowStyles.WS_BORDER | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#28-Style");
1398 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#28-ExStyle");
1403 public void FormParentedTest ()
1405 using (Form frm = new Form ()) {
1406 using (Form frm2 = new Form ()) {
1407 frm2.TopLevel = false;
1408 frm.ShowInTaskbar = false;
1409 frm2.ShowInTaskbar = false;
1410 frm2.Visible = true;
1413 EventLogger log = new EventLogger (frm);
1414 EventLogger log2 = new EventLogger (frm2);
1416 frm.Controls.Add (frm2);
1418 Assert.IsTrue (log2.EventRaised ("ParentChanged"), "#C1");
1419 Assert.IsTrue (log.EventRaised ("ControlAdded"), "#P1");
1420 Assert.AreSame (frm, frm2.Parent, "#02");
1426 public void FormPropertyTest ()
1428 Form myform = new Form ();
1429 myform.Visible = true;
1430 myform.Text = "NewForm";
1431 myform.Name = "FormTest";
1432 Assert.IsNull (myform.ActiveMdiChild, "#2");
1433 Assert.IsFalse (myform.AutoScale, "#3");
1434 Assert.IsNull (myform.CancelButton, "#6");
1435 Assert.IsTrue (myform.ControlBox, "#9");
1436 Assert.IsTrue (myform.DesktopBounds.X > 0, "#10a");
1437 Assert.IsTrue (myform.DesktopBounds.Y > 0, "#10b");
1438 Assert.AreEqual (300, myform.DesktopBounds.Height, "#10c");
1439 Assert.AreEqual (300, myform.DesktopBounds.Width, "#10d");
1440 Assert.IsTrue (myform.DesktopLocation.X > 0, "#11a");
1441 Assert.IsTrue (myform.DesktopLocation.Y > 0, "#11b");
1442 Assert.AreEqual (DialogResult.None, myform.DialogResult, "#12");
1443 Assert.AreEqual (FormBorderStyle.Sizable, myform.FormBorderStyle, "#13");
1444 Assert.IsFalse (myform.HelpButton, "#14");
1445 Assert.AreEqual ("System.Drawing.Icon", myform.Icon.GetType ().ToString (), "#15");
1446 Assert.IsFalse (myform.IsMdiChild, "#16");
1447 Assert.IsFalse (myform.IsMdiContainer, "#17");
1448 Assert.IsFalse (myform.KeyPreview, "#18");
1449 Assert.IsTrue (myform.MaximizeBox, "#19");
1450 Assert.AreEqual (0, myform.MaximumSize.Height, "#20a");
1451 Assert.AreEqual (0, myform.MaximumSize.Width, "#20b");
1452 Assert.AreEqual (0, myform.MdiChildren.Length, "#21a");
1453 Assert.AreEqual (1, myform.MdiChildren.Rank, "#21b");
1454 Assert.IsFalse (myform.MdiChildren.IsSynchronized, "#21c");
1455 Assert.IsNull (myform.MdiParent, "#22");
1456 Assert.IsNull (myform.Menu, "#23");
1457 Assert.IsNull (myform.MergedMenu, "#24");
1458 Assert.IsTrue (myform.MinimizeBox, "#25");
1459 Assert.AreEqual (0, myform.MinimumSize.Height, "#26a");
1460 Assert.AreEqual (0, myform.MinimumSize.Width, "#26b");
1461 Assert.IsTrue (myform.MinimumSize.IsEmpty, "#26c");
1462 Assert.IsFalse (myform.Modal, "#27");
1463 Assert.AreEqual (1, myform.Opacity, "#28");
1464 Assert.AreEqual (0, myform.OwnedForms.Length, "#29a");
1465 Assert.AreEqual (1, myform.OwnedForms.Rank, "#29b");
1466 Assert.IsNull (myform.Owner, "#30");
1467 Assert.IsTrue (myform.ShowInTaskbar, "#31");
1468 Assert.AreEqual (300, myform.Size.Height, "#32a");
1469 Assert.AreEqual (300, myform.Size.Width, "#32b");
1470 Assert.AreEqual (SizeGripStyle.Auto, myform.SizeGripStyle, "#33");
1471 Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, myform.StartPosition, "#34");
1472 Assert.IsTrue (myform.TopLevel, "#35");
1473 Assert.IsFalse (myform.TopMost, "#36");
1474 Assert.AreEqual (Color.Empty, myform.TransparencyKey, "#37");
1475 Assert.AreEqual (FormWindowState.Normal, myform.WindowState, "#38");
1476 Assert.AreEqual (ImeMode.NoControl, myform.ImeMode, "#39");
1481 [Category ("NotWorking")]
1482 public void ActivateTest ()
1484 Form myform = new Form ();
1485 myform.ShowInTaskbar = false;
1486 myform.Visible = true;
1487 myform.Text = "NewForm";
1488 myform.Name = "FormTest";
1490 Assert.AreEqual (true, myform.Focus (), "#40");
1495 public void AddOwnedFormTest ()
1497 Form parent = new Form ();
1498 parent.ShowInTaskbar = false;
1499 parent.Text = "NewParent";
1500 Form ownedForm = new Form ();
1501 ownedForm.ShowInTaskbar = false;
1502 ownedForm.Text = "Owned Form";
1503 parent.AddOwnedForm (ownedForm);
1505 Assert.AreEqual ("NewParent", ownedForm.Owner.Text, "#41");
1506 ownedForm.Dispose ();
1510 [Test] // bug #80020
1511 public void IsHandleCreated ()
1513 Form main = new Form ();
1515 main.IsMdiContainer = true;
1516 main.ShowInTaskbar = false;
1517 Assert.IsFalse (main.IsHandleCreated, "#1");
1519 Form child = new Form ();
1520 child.MdiParent = main;
1521 child.WindowState = FormWindowState.Maximized;
1522 Assert.IsFalse (main.IsHandleCreated, "#2");
1525 Assert.IsFalse (child.IsHandleCreated, "#3");
1526 Assert.IsFalse (main.IsHandleCreated, "#4");
1529 Assert.IsTrue (child.IsHandleCreated, "#5");
1530 Assert.IsTrue (main.IsHandleCreated, "#6");
1537 public void RemoveOwnedFormTest ()
1539 Form myform = new Form ();
1540 myform.ShowInTaskbar = false;
1541 myform.Text = "NewForm";
1542 myform.Name = "FormTest";
1543 myform.RemoveOwnedForm (myform);
1545 Assert.AreEqual (null, myform.Owner, "#44");
1550 public void SetDesktopBoundsTest ()
1552 Form myform = new Form ();
1553 myform.ShowInTaskbar = false;
1554 myform.Visible = true;
1555 myform.Text = "NewForm";
1556 myform.Name = "FormTest";
1557 myform.SetDesktopBounds (10, 10, 200 , 200);
1558 Assert.AreEqual (200, myform.DesktopBounds.Height, "#45");
1563 public void SetDesktopLocationTest ()
1565 Form myform = new Form ();
1566 myform.ShowInTaskbar = false;
1567 myform.Visible = true;
1568 myform.Text = "NewForm";
1569 myform.Name = "FormTest";
1570 myform.SetDesktopLocation (10, 10);
1571 Assert.AreEqual (10, myform.DesktopLocation.X, "#46");
1576 public void SetDialogResultOutOfRange ()
1578 Form myform = new Form ();
1579 myform.ShowInTaskbar = false;
1581 myform.DialogResult = (DialogResult) (-1);
1582 Assert.Fail ("#48");
1583 } catch (InvalidEnumArgumentException) {
1587 myform.DialogResult = (DialogResult) ((int) DialogResult.No + 1);
1588 Assert.Fail ("#49");
1589 } catch (InvalidEnumArgumentException) {
1594 void myform_set_dialogresult (object sender, EventArgs e)
1596 Form f = (Form)sender;
1598 f.DialogResult = DialogResult.OK;
1601 void myform_close (object sender, EventArgs e)
1603 Form f = (Form)sender;
1609 public void SetDialogResult ()
1611 Form myform = new Form ();
1612 myform.ShowInTaskbar = false;
1613 myform.Visible = true;
1615 myform.DialogResult = DialogResult.Cancel;
1617 Assert.IsTrue (myform.Visible, "A1");
1618 Assert.IsFalse (myform.IsDisposed, "A2");
1622 Assert.IsFalse (myform.Visible, "A3");
1623 Assert.IsTrue (myform.IsDisposed, "A4");
1625 DialogResult result;
1627 myform = new Form ();
1628 myform.ShowInTaskbar = false;
1629 myform.VisibleChanged += new EventHandler (myform_set_dialogresult);
1630 result = myform.ShowDialog ();
1632 Assert.AreEqual (result, DialogResult.OK, "A5");
1633 Assert.IsFalse (myform.Visible, "A6");
1634 Assert.IsFalse (myform.IsDisposed, "A7");
1637 myform = new Form ();
1638 myform.ShowInTaskbar = false;
1639 myform.VisibleChanged += new EventHandler (myform_close);
1640 result = myform.ShowDialog ();
1642 Assert.AreEqual (result, DialogResult.Cancel, "A8");
1643 Assert.IsFalse (myform.Visible, "A9");
1644 Assert.IsFalse (myform.IsDisposed, "A10");
1650 public void ShowDialog_Child ()
1652 Form main = new Form ();
1653 main.IsMdiContainer = true;
1654 Form child = new Form ();
1655 child.MdiParent = main;
1657 child.ShowDialog ();
1659 } catch (InvalidOperationException ex) {
1660 // Forms that are not top level forms cannot be displayed as a
1661 // modal dialog. Remove the form from any parent form before
1662 // calling ShowDialog.
1663 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1664 Assert.IsNull (ex.InnerException, "#3");
1665 Assert.IsNotNull (ex.Message, "#4");
1667 Assert.IsNull (child.Owner, "#5");
1673 public void ShowDialog_Disabled ()
1675 Form form = new Form ();
1676 form.Enabled = false;
1679 Assert.Fail ("#A1");
1680 } catch (InvalidOperationException ex) {
1681 // Forms that are not enabled cannot be displayed as a modal
1682 // dialog. Set the form's enabled property to true before
1683 // calling ShowDialog.
1684 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1685 Assert.IsNull (ex.InnerException, "#A3");
1686 Assert.IsNotNull (ex.Message, "#A4");
1688 Assert.IsNull (form.Owner, "#A5");
1691 Form main = new Form ();
1694 form.Enabled = false;
1697 Assert.Fail ("#B1");
1698 } catch (InvalidOperationException) {
1700 Assert.IsNotNull (form.Owner, "#B2");
1701 Assert.AreSame (main, form.Owner, "#B3");
1707 [Category ("NotWorking")]
1708 public void ShowDialog_Owner_Circular ()
1710 Form main = new Form ();
1711 Form child = new Form ();
1714 main.ShowDialog (child);
1716 } catch (ArgumentException ex) {
1717 // A circular control reference has been made. A control cannot
1718 // be owned or parented to itself
1719 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1720 Assert.IsNull (ex.InnerException, "#3");
1721 Assert.IsNotNull (ex.Message, "#4");
1722 Assert.IsNull (ex.ParamName, "#5");
1724 Assert.IsNull (main.Owner, "#6");
1729 [Test] // bug #80773
1730 public void ShowDialog_Owner_Self ()
1732 Form form = new Form ();
1734 form.ShowDialog (form);
1735 Assert.Fail ("#A1");
1736 } catch (ArgumentException ex) {
1737 // Forms cannot own themselves or their owners
1738 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1739 Assert.IsNull (ex.InnerException, "#A3");
1740 Assert.IsNotNull (ex.Message, "#A4");
1741 Assert.IsNotNull (ex.ParamName, "#A5");
1742 Assert.AreEqual ("owner", ex.ParamName, "#A6");
1744 Assert.IsNull (form.Owner, "#A7");
1747 Form main = new Form ();
1751 form.ShowDialog (form);
1752 Assert.Fail ("#B1");
1753 } catch (ArgumentException) {
1755 Assert.IsNotNull (form.Owner);
1756 Assert.AreSame (main, form.Owner, "#B2");
1762 public void ShowDialog_Visible ()
1764 Form form = new Form ();
1765 form.ShowInTaskbar = false;
1766 form.Visible = true;
1769 Assert.Fail ("#A1");
1770 } catch (InvalidOperationException ex) {
1771 // Forms that are already visible cannot be displayed as a modal
1772 // dialog. Set the form's visible property to false before
1773 // calling ShowDialog.
1774 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1775 Assert.IsNull (ex.InnerException, "#A3");
1776 Assert.IsNotNull (ex.Message, "#A4");
1778 Assert.IsNull (form.Owner, "#A5");
1781 Form main = new Form ();
1784 form.Visible = true;
1787 Assert.Fail ("#B1");
1788 } catch (InvalidOperationException) {
1790 Assert.IsNotNull (form.Owner, "#B2");
1791 Assert.AreSame (main, form.Owner, "#B3");
1796 [Test] // bug #80604
1797 public void VisibleOnLoad ()
1799 MockForm form = new MockForm ();
1800 form.CloseOnLoad = true;
1801 Application.Run (form);
1802 Assert.IsTrue (form.VisibleOnLoad, "#1");
1805 form = new MockForm ();
1806 form.ShowInTaskbar = false;
1808 Assert.IsTrue (form.VisibleOnLoad, "#2");
1812 [Test] // bug #80052
1813 [Category ("NotWorking")]
1814 public void Location ()
1820 Form formA = new Form ();
1821 formA.ShowInTaskbar = false;
1822 formA.StartPosition = FormStartPosition.CenterParent;
1823 formA.Location = new Point (151, 251);
1826 Assert.AreEqual (FormStartPosition.CenterParent, formA.StartPosition, "#A1");
1827 Assert.IsFalse (formA.Location.X == 151, "#A2");
1828 Assert.IsFalse (formA.Location.Y == 251, "#A3");
1830 formA.Location = new Point (311, 221);
1832 Assert.AreEqual (FormStartPosition.CenterParent, formA.StartPosition, "#A4");
1833 Assert.AreEqual (311, formA.Location.X, "#A5");
1834 Assert.AreEqual (221, formA.Location.Y, "#A6");
1842 Form formB = new Form ();
1843 formB.ShowInTaskbar = false;
1844 formB.StartPosition = FormStartPosition.CenterScreen;
1845 formB.Location = new Point (151, 251);
1848 Assert.AreEqual (FormStartPosition.CenterScreen, formB.StartPosition, "#B1");
1849 Assert.IsFalse (formB.Location.X == 151, "#B2");
1850 Assert.IsFalse (formB.Location.Y == 251, "#B3");
1852 formB.Location = new Point (311, 221);
1854 Assert.AreEqual (FormStartPosition.CenterScreen, formB.StartPosition, "#B4");
1855 Assert.AreEqual (311, formB.Location.X, "#B5");
1856 Assert.AreEqual (221, formB.Location.Y, "#B6");
1864 Form formC = new Form ();
1865 formC.ShowInTaskbar = false;
1866 formC.StartPosition = FormStartPosition.Manual;
1867 formC.Location = new Point (151, 251);
1870 Assert.AreEqual (FormStartPosition.Manual, formC.StartPosition, "#C1");
1871 Assert.AreEqual (151, formC.Location.X, "#C2");
1872 Assert.AreEqual (251, formC.Location.Y, "#C3");
1874 formC.Location = new Point (311, 221);
1876 Assert.AreEqual (FormStartPosition.Manual, formC.StartPosition, "#C4");
1877 Assert.AreEqual (311, formC.Location.X, "#C5");
1878 Assert.AreEqual (221, formC.Location.Y, "#C6");
1883 // WindowsDefaultBounds
1886 Form formD = new Form ();
1887 formD.ShowInTaskbar = false;
1888 formD.StartPosition = FormStartPosition.WindowsDefaultBounds;
1889 formD.Location = new Point (151, 251);
1892 Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, formD.StartPosition, "#D1");
1893 Assert.IsFalse (formD.Location.X == 151, "#D2");
1894 Assert.IsFalse (formD.Location.Y == 251, "#D3");
1896 formD.Location = new Point (311, 221);
1898 Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, formD.StartPosition, "#D4");
1899 Assert.AreEqual (311, formD.Location.X, "#D5");
1900 Assert.AreEqual (221, formD.Location.Y, "#D6");
1905 // WindowsDefaultLocation
1908 Form formE = new Form ();
1909 formE.ShowInTaskbar = false;
1910 formE.Location = new Point (151, 251);
1913 Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, formE.StartPosition, "#E1");
1914 Assert.IsFalse (formE.Location.X == 151, "#E2");
1915 Assert.IsFalse (formE.Location.Y == 251, "#E3");
1917 formE.Location = new Point (311, 221);
1919 Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, formE.StartPosition, "#E4");
1920 Assert.AreEqual (311, formE.Location.X, "#E5");
1921 Assert.AreEqual (221, formE.Location.Y, "#E6");
1927 public void Opacity ()
1930 using (frm = new Form ()) {
1931 Assert.AreEqual (1.0f, frm.Opacity, "#01-opacity");
1933 Assert.AreEqual (0.50f, frm.Opacity, "#02-opacity");
1934 frm.Opacity = -0.1f;
1935 Assert.AreEqual (0, frm.Opacity, "#03-opacity");
1937 Assert.AreEqual (1, frm.Opacity, "#04-opacity");
1942 public void DisposeOwnerTest ()
1944 Form f1 = new Form ();
1945 Form f2 = new Form ();
1951 Assert.IsNull (f2.Owner, "1");
1952 Assert.AreEqual (0, f1.OwnedForms.Length, "2");
1956 [ExpectedException (typeof (ObjectDisposedException))]
1957 public void AccessDisposedForm ()
1959 Form myform = new Form ();
1960 myform.ShowInTaskbar = false;
1963 myform.Close (); // this should result in the form being disposed
1964 myform.Show (); // and this line should result in the ODE being thrown
1969 public void DoDestroyHandle ()
1973 public void DoRecreateHandle ()
1979 int handle_destroyed_count;
1980 void handle_destroyed (object sender, EventArgs e)
1982 handle_destroyed_count++;
1986 public void DestroyHandleTest ()
1988 handle_destroyed_count = 0;
1990 MyForm f1 = new MyForm ();
1991 f1.HandleDestroyed += new EventHandler (handle_destroyed);
1993 f1.DoDestroyHandle ();
1994 Assert.AreEqual (1, handle_destroyed_count, "1");
1996 MyForm f2 = new MyForm ();
1997 f2.HandleDestroyed += new EventHandler (handle_destroyed);
1999 f2.DoRecreateHandle ();
2000 Assert.AreEqual (2, handle_destroyed_count, "2");
2007 public void FormClose ()
2009 Form myform = new Form ();
2010 myform.ShowInTaskbar = false;
2012 Assert.IsFalse (myform.Visible, "A1");
2013 Assert.IsFalse (myform.IsDisposed, "A2");
2017 Assert.IsTrue (myform.IsDisposed, "A3");
2019 Assert.IsFalse (myform.Visible, "A4");
2020 Assert.IsFalse (myform.IsDisposed, "A5");
2024 Assert.IsTrue (myform.Visible, "A6");
2025 Assert.IsFalse (myform.IsDisposed, "A7");
2029 Assert.IsFalse (myform.Visible, "A8");
2030 Assert.IsTrue (myform.IsDisposed, "A9");
2035 public void FormClose2 ()
2037 WMCloseWatcher f = new WMCloseWatcher ();
2038 f.ShowInTaskbar = false;
2041 Assert.IsFalse (f.Visible, "A1");
2043 Assert.AreEqual (0, f.close_count, "A2");
2045 Assert.IsTrue (f.IsDisposed, "A3");
2049 Assert.AreEqual (1, f.close_count, "A4");
2053 class WMCloseWatcher : Form {
2054 public int close_count;
2056 protected override void WndProc (ref Message msg) {
2057 if (msg.Msg == 0x0010 /* WM_CLOSE */) {
2061 base.WndProc (ref msg);
2065 class SwallowOnActivated : Form {
2066 protected override void OnActivated (EventArgs e)
2071 protected override void OnCreateControl () {
2072 base.OnCreateControl ();
2076 class EnterTest : Button {
2077 protected override void OnEnter (EventArgs e)
2083 public bool on_enter;
2087 public void OnActivateEventHandlingTest1 ()
2089 if (TestHelper.RunningOnUnix) {
2090 Assert.Ignore ("Relies on form.Show() synchronously generating WM_ACTIVATE");
2093 SwallowOnActivated f = new SwallowOnActivated ();
2095 f.ShowInTaskbar = false;
2097 EnterTest c = new EnterTest ();
2102 Assert.IsTrue (c.on_enter, "1");
2109 public void FormClosingEvents ()
2112 Form f = new Form ();
2113 string events = string.Empty;
2115 f.Closing += new CancelEventHandler (delegate (Object obj, CancelEventArgs e) { events += ("Closing;"); });
2116 f.FormClosing += new FormClosingEventHandler (delegate (Object obj, FormClosingEventArgs e) { events += string.Format ("FormClosing [Reason:{0} - Cancel:{1}]", e.CloseReason, e.Cancel); });
2121 Assert.AreEqual ("Closing;FormClosing [Reason:UserClosing - Cancel:False]", events, "A1");
2125 public void FormClosingEventsCancel ()
2127 // Shows that setting Cancel in Closing flows through to FormClosing
2128 Form f = new Form ();
2129 string events = string.Empty;
2131 f.Closing += new CancelEventHandler (delegate (Object obj, CancelEventArgs e) { events += ("Closing;"); e.Cancel = true; });
2132 f.FormClosing += new FormClosingEventHandler (delegate (Object obj, FormClosingEventArgs e) { events += string.Format("FormClosing [Reason:{0} - Cancel:{1}]", e.CloseReason, e.Cancel); e.Cancel = false; });
2137 Assert.AreEqual ("Closing;FormClosing [Reason:UserClosing - Cancel:True]", events, "A1");
2141 public void FormClosedEvents ()
2144 Form f = new Form ();
2145 string events = string.Empty;
2147 f.Closed += new EventHandler (delegate (Object obj, EventArgs e) { events += ("Closed;"); });
2148 f.FormClosed += new FormClosedEventHandler (delegate (Object obj, FormClosedEventArgs e) { events += string.Format ("FormClosed [Reason:{0}]", e.CloseReason); });
2153 Assert.AreEqual ("Closed;FormClosed [Reason:UserClosing]", events, "A1");
2157 public void ShowWithOwner ()
2159 Form f = new Form ();
2160 Button b = new Button ();
2163 Form f2 = new Form ();
2167 Assert.AreSame (f, f2.Owner, "A1");
2173 Assert.AreSame (f, f2.Owner, "A2");
2176 Button b2 = new Button ();
2180 Assert.AreEqual (null, f2.Owner, "A3");
2185 Assert.AreEqual (null, f2.Owner, "A4");
2192 [ExpectedException (typeof (InvalidOperationException))]
2193 public void ShowWithOwnerIOE ()
2195 using (Form f = new Form ()) {
2200 [Test] // Bug #79959, #80574, #80791
2201 [Category ("NotWorking")]
2202 public void BehaviorResizeOnBorderStyleChanged ()
2204 // Marked NotWorking because the ClientSize is dependent on the WM.
2205 // The values below match XP Luna to make sure our behavior is the same.
2206 Form f = new Form ();
2207 f.ShowInTaskbar = false;
2210 Assert.AreEqual (true, f.IsHandleCreated, "A0");
2212 Assert.AreEqual (new Size (300, 300), f.Size, "A1");
2213 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A2");
2215 f.FormBorderStyle = FormBorderStyle.Fixed3D;
2216 Assert.AreEqual (new Size (302, 302), f.Size, "A3");
2217 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4");
2219 f.FormBorderStyle = FormBorderStyle.FixedDialog;
2220 Assert.AreEqual (new Size (298, 298), f.Size, "A5");
2221 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A6");
2223 f.FormBorderStyle = FormBorderStyle.FixedSingle;
2224 Assert.AreEqual (new Size (298, 298), f.Size, "A7");
2225 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A8");
2227 f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
2228 Assert.AreEqual (new Size (298, 290), f.Size, "A9");
2229 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A0");
2231 f.FormBorderStyle = FormBorderStyle.None;
2232 Assert.AreEqual (new Size (292, 266), f.Size, "A11");
2233 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A12");
2235 f.FormBorderStyle = FormBorderStyle.SizableToolWindow;
2236 Assert.AreEqual (new Size (300, 292), f.Size, "A13");
2237 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A14");
2239 f.FormBorderStyle = FormBorderStyle.Sizable;
2240 Assert.AreEqual (new Size (300, 300), f.Size, "A15");
2241 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A16");
2246 [Test] // Bug #80574, #80791
2247 [Category ("NotWorking")]
2248 public void BehaviorResizeOnBorderStyleChangedNotVisible ()
2250 // Marked NotWorking because the ClientSize is dependent on the WM.
2251 // The values below match XP Luna to make sure our behavior is the same.
2252 Form f = new Form ();
2253 f.ShowInTaskbar = false;
2255 Assert.AreEqual (false, f.IsHandleCreated, "A0");
2257 Assert.AreEqual (new Size (300, 300), f.Size, "A1");
2258 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A2");
2260 f.FormBorderStyle = FormBorderStyle.Fixed3D;
2261 Assert.AreEqual (new Size (300, 300), f.Size, "A3");
2262 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4");
2264 f.FormBorderStyle = FormBorderStyle.FixedDialog;
2265 Assert.AreEqual (new Size (300, 300), f.Size, "A5");
2266 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A6");
2268 f.FormBorderStyle = FormBorderStyle.FixedSingle;
2269 Assert.AreEqual (new Size (300, 300), f.Size, "A7");
2270 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A8");
2272 f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
2273 Assert.AreEqual (new Size (300, 300), f.Size, "A9");
2274 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A0");
2276 f.FormBorderStyle = FormBorderStyle.None;
2277 Assert.AreEqual (new Size (300, 300), f.Size, "A11");
2278 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A12");
2280 f.FormBorderStyle = FormBorderStyle.SizableToolWindow;
2281 Assert.AreEqual (new Size (300, 300), f.Size, "A13");
2282 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A14");
2284 f.FormBorderStyle = FormBorderStyle.Sizable;
2285 Assert.AreEqual (new Size (300, 300), f.Size, "A15");
2286 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A16");
2289 [Test] // Bug #80574, #80791
2290 [Category ("NotWorking")]
2291 public void MoreBehaviorResizeOnBorderStyleChangedNotVisible ()
2293 // Marked NotWorking because the ClientSize is dependent on the WM.
2294 // The values below match XP Luna to make sure our behavior is the same.
2295 Form f = new Form ();
2296 f.ShowInTaskbar = false;
2301 Assert.AreEqual (true, f.IsHandleCreated, "A0");
2303 f.FormBorderStyle = FormBorderStyle.Sizable;
2304 Assert.AreEqual (new Size (300, 300), f.Size, "A1");
2305 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A2");
2306 f.FormBorderStyle = FormBorderStyle.None;
2307 Assert.AreEqual (new Size (292, 266), f.Size, "A3");
2308 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4");
2312 [Test] // Bug #81582
2313 [Category ("NotWorking")]
2314 public void GotFocusWithoutCallingOnLoadBase ()
2316 NoOnLoadBaseForm f = new NoOnLoadBaseForm ();
2318 Assert.AreEqual (true, f.got_focus_called, "H1");
2322 private class NoOnLoadBaseForm : Form
2324 public bool got_focus_called = false;
2326 public NoOnLoadBaseForm ()
2328 TreeView tv = new TreeView ();
2329 tv.GotFocus += new EventHandler (tv_GotFocus);
2333 void tv_GotFocus (object sender, EventArgs e)
2335 got_focus_called = true;
2338 protected override void OnLoad (EventArgs e)
2343 [Test] // bug #339641
2344 public void ChildFocused ()
2346 if (TestHelper.RunningOnUnix) {
2347 Assert.Ignore ("Relies on form.Show() synchronously generating WM_ACTIVATE");
2349 using (Form f = new TimeBombedForm ()) {
2350 TreeView tv = new TreeView ();
2351 EventLogger log = new EventLogger (tv);
2352 tv.GotFocus += new EventHandler (tv_GotFocus);
2353 f.Activated += new EventHandler (f_Activated);
2354 f.Controls.Add (tv);
2356 Assert.IsTrue (log.EventRaised ("GotFocus"), "#01");
2360 void f_Activated (object sender, EventArgs e)
2362 //Console.WriteLine (" ACTIVATED");
2363 //Console.WriteLine (Environment.StackTrace);
2366 void tv_GotFocus (object sender, EventArgs e)
2368 //Console.WriteLine (Environment.StackTrace);
2371 [Test] // bug #80773
2372 public void DontSetOwnerOnShowDialogException ()
2374 Form f = new Form ();
2375 f.ShowInTaskbar = false;
2377 try { f.ShowDialog (f); }
2380 Assert.AreEqual (null, f.Owner, "H1");
2386 public void MinimumWindowSize ()
2388 Form f = new Form ();
2389 f.ShowInTaskbar = false;
2392 f.Size = new Size (0, 0);
2393 Assert.AreEqual (SystemInformation.MinimumWindowSize, f.Size);
2399 public void Bug82470 ()
2401 Form f = new Form ();
2402 f.Load += new EventHandler (Form_LoadAndHide);
2405 Assert.AreEqual (true, f.Visible, "A1");
2410 private void Form_LoadAndHide (object sender, EventArgs e)
2412 ((Form)sender).Visible = false;
2417 public void AutoSizeGrowOnly ()
2419 Form f = new Form ();
2420 f.ShowInTaskbar = false;
2423 Button b = new Button ();
2424 b.Size = new Size (200, 200);
2425 b.Location = new Point (200, 200);
2430 Assert.AreEqual (new Size (403, 403), f.ClientSize, "A1");
2432 f.Controls.Remove (b);
2433 Assert.AreEqual (new Size (403, 403), f.ClientSize, "A2");
2439 public void AutoSizeReset ()
2441 Form f = new Form ();
2442 f.ShowInTaskbar = false;
2444 Button b = new Button ();
2445 b.Size = new Size (200, 200);
2446 b.Location = new Point (200, 200);
2451 Size start_size = f.ClientSize;
2454 Assert.AreEqual (new Size (403, 403), f.ClientSize, "A1");
2457 Assert.AreEqual (start_size, f.ClientSize, "A2");
2462 public void AutoSizeGrowAndShrink ()
2464 Form f = new Form ();
2465 f.ShowInTaskbar = false;
2467 f.AutoSizeMode = AutoSizeMode.GrowAndShrink;
2471 // Make sure form shrunk
2472 Assert.IsTrue (f.ClientSize.Width < 150, "A1");
2473 Assert.IsTrue (f.ClientSize.Height < 150, "A1-2");
2475 Button b = new Button ();
2476 b.Size = new Size (200, 200);
2477 b.Location = new Point (0, 0);
2480 Assert.AreEqual (new Size (203, 203), f.ClientSize, "A2");
2485 public void GetScaledBoundsTest ()
2487 if (TestHelper.RunningOnUnix)
2488 Assert.Ignore ("Depends on WM decoration sizes, values correspond to windows");
2490 ScaleForm c = new ScaleForm ();
2492 Rectangle r = new Rectangle (100, 200, 300, 400);
2494 Assert.AreEqual (new Rectangle (100, 200, 584, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A1");
2495 Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A2");
2496 Assert.AreEqual (new Rectangle (100, 200, 584, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A3");
2497 Assert.AreEqual (new Rectangle (100, 200, 300, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A4");
2498 Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A5");
2499 Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A6");
2501 Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (1f, 1f), BoundsSpecified.All), "A6-2");
2502 Assert.AreEqual (new Rectangle (100, 200, 584, 764), c.PublicGetScaledBounds (r, new SizeF (2f, 2f), BoundsSpecified.All), "A7");
2503 Assert.AreEqual (new Rectangle (100, 200, 868, 1128), c.PublicGetScaledBounds (r, new SizeF (3f, 3f), BoundsSpecified.All), "A8");
2504 Assert.AreEqual (new Rectangle (100, 200, 1152, 1492), c.PublicGetScaledBounds (r, new SizeF (4f, 4f), BoundsSpecified.All), "A9");
2505 Assert.AreEqual (new Rectangle (100, 200, 158, 218), c.PublicGetScaledBounds (r, new SizeF (.5f, .5f), BoundsSpecified.All), "A10");
2509 public void MethodScaleControl ()
2511 if (TestHelper.RunningOnUnix)
2512 Assert.Ignore ("Depends on WM decoration sizes, values correspond to windows");
2514 ScaleForm f = new ScaleForm ();
2515 f.Location = new Point (5, 10);
2517 Assert.AreEqual (new Rectangle (5, 10, 300, 300), f.Bounds, "A1");
2519 f.PublicScaleControl (new SizeF (2.0f, 2.0f), BoundsSpecified.All);
2520 Assert.AreEqual (new Rectangle (5, 10, 584, 564), f.Bounds, "A2");
2522 f.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Location);
2523 Assert.AreEqual (new Rectangle (5, 10, 584, 564), f.Bounds, "A3");
2525 f.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Size);
2526 Assert.AreEqual (new Rectangle (5, 10, 300, 300), f.Bounds, "A4");
2528 f.PublicScaleControl (new SizeF (2.5f, 2.5f), BoundsSpecified.Size);
2529 Assert.AreEqual (new Rectangle (5, 10, 726, 696), f.Bounds, "A5");
2531 f.PublicScaleControl (new SizeF (.3f, .3f), BoundsSpecified.Size);
2532 Assert.AreEqual (new Rectangle (5, 10, 229, 234), f.Bounds, "A6");
2537 private class ScaleForm : Form
2539 public Rectangle PublicGetScaledBounds (Rectangle bounds, SizeF factor, BoundsSpecified specified)
2541 return base.GetScaledBounds (bounds, factor, specified);
2544 public void PublicScaleControl (SizeF factor, BoundsSpecified specified)
2546 base.ScaleControl (factor, specified);
2551 public void Bug325436 ()
2553 Form f = new Form ();
2554 f.ShowInTaskbar = false;
2555 f.ClientSize = new Size (320, 40);
2556 f.ControlBox = false;
2557 f.FormBorderStyle = FormBorderStyle.None;
2558 f.MaximizeBox = false;
2559 f.MinimizeBox = false;
2562 Assert.AreEqual (new Size (320, 40), f.ClientSize, "A1");
2566 f.ShowInTaskbar = false;
2567 f.ControlBox = false;
2568 f.FormBorderStyle = FormBorderStyle.None;
2569 f.MaximizeBox = false;
2570 f.MinimizeBox = false;
2571 f.ClientSize = new Size(320, 40);
2574 Assert.AreEqual (new Size (320, 40), f.ClientSize, "A2");
2579 #region PreferredSize
2581 public void PreferredSize ()
2583 PreferredSizeForm form = new PreferredSizeForm ();
2584 form.AutoSize = true;
2585 Control control = new Control ();
2586 form.Controls.Add (control);
2587 control.Size = new Size (500, 500);
2589 form.Controls.Clear ();
2594 private class PreferredSizeForm : Form
2598 Assert.AreEqual (SizeFromClientSize (new Size (503, 503)), PreferredSize, "1");
2601 public void Test2 ()
2603 Assert.AreEqual (SizeFromClientSize (new Size (0, 0)), PreferredSize, "1");
2608 private class MockForm : Form
2610 public bool CloseOnLoad {
2611 get { return _closeOnLoad; }
2612 set { _closeOnLoad = value; }
2615 public bool VisibleOnLoad {
2616 get { return _visibleOnLoad; }
2619 protected override void OnLoad(EventArgs e) {
2621 _visibleOnLoad = Visible;
2626 private bool _closeOnLoad;
2627 private bool _visibleOnLoad;
2630 private class MockButton : Button
2632 public MockButton (bool notify)
2637 public bool Notify {
2638 get { return _notify; }
2639 set { _notify = value; }
2642 public bool IsDefaultButton
2644 get { return base.IsDefault; }
2645 set { base.IsDefault = value; }
2648 public override void NotifyDefault (bool value)
2651 base.NotifyDefault (value);
2654 private bool _notify;
2657 private class ButtonControl : IButtonControl
2659 public DialogResult DialogResult {
2660 get { return _dialogResult; }
2661 set { _dialogResult = value; }
2664 public bool IsDefaultButton {
2665 get { return _isDefault; }
2668 public void NotifyDefault (bool value)
2673 public void PerformClick ()
2677 private bool _isDefault;
2678 private DialogResult _dialogResult = DialogResult.None;
2683 public void RestoreBounds ()
2685 Form f = new Form ();
2688 Assert.AreEqual (new Size (300, 300), f.RestoreBounds.Size, "A1");
2691 f.Location = new Point (0, 0);
2692 Assert.AreEqual (new Rectangle (0, 0, 300, 300), f.RestoreBounds, "A2");
2695 f.Size = new Size (250, 250);
2696 Assert.AreEqual (new Rectangle (0, 0, 250, 250), f.RestoreBounds, "A3");
2698 // Minimize the form
2699 f.WindowState = FormWindowState.Minimized;
2700 Assert.AreEqual (new Rectangle (0, 0, 250, 250), f.RestoreBounds, "A4");
2702 // Move the form (while minimized)
2703 f.Location = new Point (10, 10);
2704 Assert.AreEqual (new Rectangle (10, 10, 250, 250), f.RestoreBounds, "A5");
2706 // Resize the form (while minimized)
2707 f.Size = new Size (275, 275);
2708 Assert.AreEqual (new Rectangle (10, 10, 275, 275), f.RestoreBounds, "A6");
2710 // Maximize the form
2711 f.WindowState = FormWindowState.Maximized;
2712 Assert.AreEqual (new Rectangle (10, 10, 275, 275), f.RestoreBounds, "A7");
2714 // Move the form (while maximized)
2715 f.Location = new Point (20, 20);
2716 Assert.AreEqual (new Rectangle (20, 20, 275, 275), f.RestoreBounds, "A8");
2718 // Resize the form (while maximized)
2719 f.Size = new Size (285, 285);
2720 Assert.AreEqual (new Rectangle (20, 20, 285, 285), f.RestoreBounds, "A9");
2725 [Test] // Bug 353827
2726 public void AutoScaleModeTest ()
2728 Form f = new Form ();
2730 // AutoScale starts off true
2731 Assert.AreEqual (true, f.AutoScale, "A1");
2733 // Setting AutoScaleMode turns AutoScale off
2734 f.AutoScaleMode = AutoScaleMode.Font;
2735 Assert.AreEqual (false, f.AutoScale, "A2");
2736 Assert.AreEqual (AutoScaleMode.Font, f.AutoScaleMode, "A3");
2738 // Changing Font resets AutoScaleBaseSize..
2739 f.Font = new Font ("Arial", 10);
2740 Assert.AreEqual (RoundSizeF (Form.GetAutoScaleSize (f.Font)), f.AutoScaleBaseSize, "A4");
2742 f.Font = new Font ("Arial", 12);
2743 Assert.AreEqual (RoundSizeF (Form.GetAutoScaleSize (f.Font)), f.AutoScaleBaseSize, "A5");
2745 // ..Until AutoScaleBaseSize is explicitly set
2746 f.AutoScaleBaseSize = new Size (5, 13);
2747 Assert.AreEqual (new Size (5, 13), f.AutoScaleBaseSize, "A6");
2749 f.Font = new Font ("Arial", 14F);
2750 Assert.IsTrue (RoundSizeF (Form.GetAutoScaleSize (f.Font)) != f.AutoScaleBaseSize, "A5");
2755 private Size RoundSizeF (SizeF sizef)
2757 return new Size ((int)Math.Round (sizef.Width), (int)Math.Round (sizef.Height));
2760 [Test] // Bug 354669
2761 public void AutoScaleDetails ()
2763 ProtectedForm f = new ProtectedForm ();
2768 // First AutoScaleMode shouldn't reset AutoScaleDimensions
2769 f.AutoScaleDimensions = new SizeF (3F, 3F);
2770 f.AutoScaleMode = AutoScaleMode.Font;
2771 Assert.AreEqual (new SizeF (3F, 3F), f.AutoScaleDimensions, "A1");
2773 // Subsequent calls will reset it to 0, 0
2774 f.AutoScaleMode = AutoScaleMode.Dpi;
2775 Assert.AreEqual (SizeF.Empty, f.AutoScaleDimensions, "A2");
2779 // CurrentAutoScaleDimensions should be nonzero
2780 Assert.IsFalse (f.CurrentAutoScaleDimensions == SizeF.Empty, "A3");
2782 // AutoScaleDimensions and CurrentAutoScaleDimensions should match after ResumeLayout
2783 Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A4");
2785 // CurrentAutoScaleDimensions should match AutoScaleDimensions for AutoScaleMode.None
2787 f.AutoScaleMode = AutoScaleMode.None;
2788 f.AutoScaleDimensions = new SizeF (5F, 5F);
2790 Assert.AreEqual (new SizeF (5F, 5F), f.AutoScaleDimensions, "A5");
2791 Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A6");
2793 // ResumeLayout changes nothing
2796 Assert.AreEqual (new SizeF (5F, 5F), f.AutoScaleDimensions, "A7");
2797 Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A8");
2799 // AutoScaleFactor should be ~2,2 if PerformAutoScale hasn't run
2800 f.ClientSize = new Size (150, 150);
2802 f.AutoScaleMode = AutoScaleMode.Dpi;
2803 f.AutoScaleDimensions = new SizeF (f.CurrentAutoScaleDimensions.Width / 2F, f.CurrentAutoScaleDimensions.Height / 2F);
2804 f.ClientSize = new Size (200, 200);
2806 Assert.AreEqual (new Size (2, 2), RoundSizeF (f.GetPublicAutoScaleFactor ()), "A9");
2808 // AutoScaleFactor should be 1 after ResumeLayout
2811 Assert.AreEqual (new SizeF (1F, 1F), f.GetPublicAutoScaleFactor (), "A10");
2812 Assert.AreEqual (new Size (400, 400), f.ClientSize, "A11");
2814 // PerformAutoScale happens immediately when layout not suspended
2815 f.ClientSize = new Size (125, 125);
2816 f.AutoScaleDimensions = new SizeF (f.CurrentAutoScaleDimensions.Width / 2F, f.CurrentAutoScaleDimensions.Height / 2F);
2817 Assert.AreEqual (new Size (250, 250), f.ClientSize, "A12");
2822 private class ProtectedForm : Form
2824 public SizeF GetPublicAutoScaleFactor ()
2826 return AutoScaleFactor;
2830 [Test] // Bug #355703
2831 public void AutoScaleSticks ()
2833 Form f = new Form ();
2835 f.AutoScale = false;
2836 Assert.AreEqual (false, f.AutoScale, "A1");
2839 Assert.AreEqual (true, f.AutoScale, "A2");
2841 f.AutoScaleMode = AutoScaleMode.None;
2842 Assert.AreEqual (false, f.AutoScale, "A3");
2846 [Test] // Bug #359098
2847 public void AutoScaleBounds ()
2849 AutoScaleForm a = new AutoScaleForm (false);
2851 Assert.AreEqual (new Size (213, 121), a.ClientSize, "A0");
2852 Assert.AreEqual (new Rectangle ( 5, 107, 132, 9), new Rectangle (a.hScrollBar1.Location, a.hScrollBar1.Size), "A1");
2853 Assert.AreEqual (new Rectangle (151, 74, 60, 44), new Rectangle (a.treeView1.Location, a.treeView1.Size), "A2");
2854 Assert.AreEqual (new Rectangle (197, 21, 9, 39), new Rectangle (a.vScrollBar1.Location, a.vScrollBar1.Size), "A3");
2855 Assert.AreEqual (new Rectangle (139, 21, 54, 49), new Rectangle (a.listView1.Location, a.listView1.Size), "A4");
2856 Assert.AreEqual (new Rectangle ( 70, 5, 65, 37), new Rectangle (a.textBox2.Location, a.textBox2.Size), "A5");
2857 Assert.AreEqual (new Rectangle (139, 5, 70, 0), new Rectangle (a.comboBox1.Location, new Size (a.comboBox1.Width, 0)), "A6");
2858 Assert.AreEqual (new Rectangle ( 5, 77, 43, 13), new Rectangle (a.button2.Location, a.button2.Size), "A7");
2859 Assert.AreEqual (new Rectangle ( 70, 44, 65, 37), new Rectangle (a.richTextBox1.Location, a.richTextBox1.Size), "A8");
2860 Assert.AreEqual (new Rectangle ( 53, 86, 21, 7), new Rectangle (a.label1.Location,a.label1.Size), "A9");
2861 Assert.AreEqual (new Rectangle ( 65, 84, 58, 0), new Rectangle (a.textBox1.Location, new Size (a.textBox1.Width, 0)), "A10");
2862 Assert.AreEqual (new Rectangle ( 5, 63, 43, 13), new Rectangle (a.button1.Location, a.button1.Size), "A11");
2863 Assert.AreEqual (new Rectangle ( 5, 5, 60, 47), new Rectangle (a.listBox1.Location, a.listBox1.Size), "A12");
2867 a = new AutoScaleForm (true);
2869 Assert.AreEqual (new Size (184, 104), a.ClientSize, "B0");
2870 Assert.AreEqual (new Rectangle ( 4, 92, 114, 16), new Rectangle (a.hScrollBar1.Location, a.hScrollBar1.ClientSize), "B1");
2871 Assert.AreEqual (new Rectangle (130, 64, 50, 36), new Rectangle (a.treeView1.Location, a.treeView1.ClientSize), "B2");
2872 Assert.AreEqual (new Rectangle (170, 18, 16, 34), new Rectangle (a.vScrollBar1.Location, a.vScrollBar1.ClientSize), "B3");
2873 Assert.AreEqual (new Rectangle (120, 18, 44, 40), new Rectangle (a.listView1.Location, a.listView1.ClientSize), "B4");
2874 Assert.AreEqual (new Rectangle ( 60, 4, 54, 30), new Rectangle (a.textBox2.Location, a.textBox2.ClientSize), "B5");
2875 Assert.AreEqual (new Rectangle (120, 4, 62, 0), new Rectangle (a.comboBox1.Location, new Size (a.comboBox1.ClientSize.Width, 0)), "B6");
2876 Assert.AreEqual (new Rectangle ( 4, 66, 38, 12), new Rectangle (a.button2.Location, a.button2.ClientSize), "B7");
2877 Assert.AreEqual (new Rectangle ( 60, 38, 54, 30), new Rectangle (a.richTextBox1.Location, a.richTextBox1.ClientSize), "B8");
2878 Assert.AreEqual (new Rectangle ( 46, 74, 18, 6), new Rectangle (a.label1.Location,a.label1.ClientSize), "B9");
2879 Assert.AreEqual (new Rectangle ( 56, 72, 48, 0), new Rectangle (a.textBox1.Location, new Size (a.textBox1.ClientSize.Width, 0)), "B10");
2880 Assert.AreEqual (new Rectangle ( 4, 54, 38, 12), new Rectangle (a.button1.Location, a.button1.ClientSize), "B11");
2881 Assert.AreEqual (new Rectangle ( 4, 4, 50, 39), new Rectangle (a.listBox1.Location, a.listBox1.ClientSize), "B12");
2887 public void SettingIconToNull ()
2889 Form form = new Form ();
2890 Assert.IsNotNull (form.Icon, "1");
2892 Assert.IsNotNull (form.Icon, "2");
2896 [Category ("NotWorking")]
2897 public void MinimizedWindowSize ()
2899 Form form = new Form ();
2900 form.WindowState = FormWindowState.Minimized;
2902 Assert.AreEqual (SystemInformation.MinimizedWindowSize, form.Size, "1");
2906 form.WindowState = FormWindowState.Minimized;
2907 Assert.AreEqual (SystemInformation.MinimizedWindowSize, form.Size, "2");
2912 public class TimeBombedForm : Form
2915 public bool CloseOnPaint;
2916 public string Reason;
2917 public TimeBombedForm ()
2919 timer = new Timer ();
2920 timer.Interval = 500;
2921 timer.Tick += new EventHandler (timer_Tick);
2925 void timer_Tick (object sender, EventArgs e)
2931 protected override void OnPaint (PaintEventArgs pevent)
2933 base.OnPaint (pevent);
2941 public class AutoScaleForm : Form
2943 public ListBox listBox1 = new ListBox ();
2944 public ComboBox comboBox1 = new ComboBox ();
2945 public Button button1 = new Button ();
2946 public Button button2 = new Button ();
2947 public Label label1 = new Label ();
2948 public TextBox textBox1 = new TextBox ();
2949 public TextBox textBox2 = new TextBox ();
2950 public RichTextBox richTextBox1 = new RichTextBox ();
2951 public ListView listView1 = new ListView ();
2952 public TreeView treeView1 = new TreeView ();
2953 public VScrollBar vScrollBar1 = new VScrollBar ();
2954 public HScrollBar hScrollBar1 = new HScrollBar ();
2956 public AutoScaleForm (bool use_new_auto_scale)
2958 ShowInTaskbar = false;
2962 listBox1.IntegralHeight = false;
2963 listBox1.SetBounds (8, 8, 104, 82);
2964 comboBox1.SetBounds (240, 8, 121, 21);
2965 button1.SetBounds (8, 108, 75, 23);
2966 button2.SetBounds (8, 132, 75, 23);
2967 label1.SetBounds (92, 148, 35, 13);
2968 textBox1.SetBounds (112, 144, 100, 20);
2969 textBox2.Multiline = true;
2970 textBox2.SetBounds (120, 8, 112, 64);
2971 richTextBox1.SetBounds (120, 76, 112, 64);
2972 listView1.SetBounds (240, 36, 92, 84);
2973 treeView1.SetBounds (260, 128, 104, 76);
2974 vScrollBar1.SetBounds (340, 36, 16, 68);
2975 hScrollBar1.SetBounds (8, 184, 228, 16);
2977 ClientSize = new Size (368, 209);
2979 Controls.AddRange ( new Control [] { listBox1, comboBox1, button1, button2, label1, textBox1,
2980 textBox2, richTextBox1, listView1, treeView1, vScrollBar1, hScrollBar1 } );
2982 if (use_new_auto_scale) {
2984 AutoScaleMode = AutoScaleMode.Dpi;
2985 SizeF s = CurrentAutoScaleDimensions;
2986 AutoScaleDimensions = new SizeF (s.Width * 2, s.Height * 2);
2991 SizeF s = Form.GetAutoScaleSize (Font);
2992 AutoScaleBaseSize = new Size ((int)Math.Round (s.Width) * 2, (int)s.Height * 2);
2995 ResumeLayout (false);