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");
659 Assert.AreEqual (1, log.CountEvents ("Closing"), "#B1");
661 Assert.AreEqual (1, log.CountEvents ("FormClosing"), "#B2");
663 Assert.AreEqual (1, log.CountEvents ("HandleDestroyed"), "#B3");
665 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");
1146 [Test] // bug #80791
1147 public void ClientSizeTest ()
1149 Form form = new Form ();
1150 Assert.IsFalse (form.ClientSize == form.Size);
1153 [Test] // bug #80574
1154 [Category ("NotWorking")]
1155 public void FormBorderStyleTest ()
1157 Form form = new Form ();
1158 Rectangle boundsBeforeBorderStyleChange = form.Bounds;
1159 Rectangle clientRectangleBeforeBorderStyleChange = form.ClientRectangle;
1160 form.FormBorderStyle = FormBorderStyle.None;
1161 Assert.AreEqual (form.Bounds, boundsBeforeBorderStyleChange, "#A1");
1162 Assert.AreEqual (form.ClientRectangle, clientRectangleBeforeBorderStyleChange, "#A2");
1164 form.Visible = true;
1165 form.FormBorderStyle = FormBorderStyle.Sizable;
1166 boundsBeforeBorderStyleChange = form.Bounds;
1167 clientRectangleBeforeBorderStyleChange = form.ClientRectangle;
1168 form.FormBorderStyle = FormBorderStyle.None;
1169 Assert.IsFalse (form.Bounds == boundsBeforeBorderStyleChange, "#B1");
1170 Assert.AreEqual (form.ClientRectangle, clientRectangleBeforeBorderStyleChange, "#B2");
1172 form.Visible = false;
1173 form.FormBorderStyle = FormBorderStyle.Sizable;
1174 boundsBeforeBorderStyleChange = form.Bounds;
1175 clientRectangleBeforeBorderStyleChange = form.ClientRectangle;
1176 form.FormBorderStyle = FormBorderStyle.None;
1177 Assert.IsFalse (form.Bounds == boundsBeforeBorderStyleChange, "#C1");
1178 Assert.AreEqual (form.ClientRectangle, clientRectangleBeforeBorderStyleChange, "#C2");
1182 [Category ("NotWorking")]
1183 public void MaximizedParentedFormTest ()
1185 using (Form Main = new Form ()) {
1186 Form Child = new Form ();
1187 Child.TopLevel = false;
1188 Main.Controls.Add (Child);
1189 Main.ShowInTaskbar = false;
1192 Child.WindowState = FormWindowState.Maximized;
1193 Child.Visible = true;
1194 // The exact negative value depends on the border with, but it should always be < 0.
1195 Assert.IsTrue (Child.Location.X < 0 && Child.Location.Y < 0, "#A1");
1199 [Category ("NotWorking")]
1200 public void ParentedFormEventTest ()
1203 using (Form Main = new Form ()) {
1204 Form Child = new Form ();
1205 Child.TopLevel = false;
1206 Child.Visible = true;
1207 Main.ShowInTaskbar = false;
1210 EventLogger log = new EventLogger (Child);
1211 Assert.AreEqual (true, Child.Visible, "#A0");
1212 Main.Controls.Add (Child);
1213 Assert.AreEqual (true, Child.Visible, "#B0");
1214 Assert.AreEqual ("ParentChanged;BindingContextChanged;Layout;VisibleChanged;BindingContextChanged;BindingContextChanged", log.EventsJoined (), "#B1");
1218 [NUnit.Framework.Category ("NotWorking")]
1219 public void FormCreateParamsStyleTest ()
1223 using (frm = new Form ()) {
1224 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles) TestHelper.GetCreateParams (frm).Style), "#01-Style");
1225 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles) TestHelper.GetCreateParams (frm).ExStyle), "#01-ExStyle");
1228 using (frm = new Form ()) {
1229 frm.AllowDrop = !frm.AllowDrop;
1230 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#02-Style");
1231 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#02-ExStyle");
1234 using (frm = new Form ()) {
1235 frm.AllowTransparency = !frm.AllowTransparency;
1236 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#03-Style");
1237 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_LAYERED, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#03-ExStyle");
1240 using (frm = new Form ()) {
1242 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#04-Style");
1243 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_LAYERED, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#04-ExStyle");
1246 using (frm = new Form ()) {
1247 frm.TransparencyKey = Color.Cyan;
1248 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#05-Style");
1249 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_LAYERED, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#05-ExStyle");
1252 using (frm = new Form ()) {
1253 frm.CausesValidation = !frm.CausesValidation;
1254 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#06-Style");
1255 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#06-ExStyle");
1258 using (frm = new Form ()) {
1259 frm.ControlBox = !frm.ControlBox;
1260 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_THICKFRAME | WindowStyles.WS_BORDER | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#07-Style");
1261 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#07-ExStyle");
1264 using (frm = new Form ()) {
1266 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#08-Style");
1267 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#08-ExStyle");
1270 using (frm = new Form ()) {
1271 frm.FormBorderStyle = FormBorderStyle.Fixed3D;
1272 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#10-Style");
1273 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CLIENTEDGE | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#10-ExStyle");
1276 using (frm = new Form ()) {
1277 frm.FormBorderStyle = FormBorderStyle.FixedDialog;
1278 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#11-Style");
1279 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#11-ExStyle");
1282 using (frm = new Form ()) {
1283 frm.FormBorderStyle = FormBorderStyle.FixedSingle;
1284 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#12-Style");
1285 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#12-ExStyle");
1288 using (frm = new Form ()) {
1289 frm.FormBorderStyle = FormBorderStyle.FixedToolWindow;
1290 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#13-Style");
1291 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_TOOLWINDOW | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#13-ExStyle");
1294 using (frm = new Form ()) {
1295 frm.FormBorderStyle = FormBorderStyle.None;
1296 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#14-Style");
1297 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#14-ExStyle");
1300 using (frm = new Form ()) {
1301 frm.FormBorderStyle = FormBorderStyle.Sizable;
1302 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#15-Style");
1303 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#15-ExStyle");
1306 using (frm = new Form ()) {
1307 frm.FormBorderStyle = FormBorderStyle.SizableToolWindow;
1308 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#16-Style");
1309 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_TOOLWINDOW | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#16-ExStyle");
1312 using (frm = new Form ()) {
1313 frm.HelpButton = !frm.HelpButton;
1314 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#17-Style");
1315 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#17-ExStyle");
1318 using (frm = new Form ()) {
1320 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#18-Style");
1321 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#18-ExStyle");
1324 using (frm = new Form ()) {
1325 frm.Icon = SystemIcons.Asterisk;
1326 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#19-Style");
1327 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#19-ExStyle");
1330 using (frm = new Form ()) {
1331 frm.IsMdiContainer = !frm.IsMdiContainer;
1332 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#20-Style");
1333 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#20-ExStyle");
1336 using (frm = new Form ()) {
1337 frm.MaximizeBox = !frm.MaximizeBox;
1338 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_GROUP | WindowStyles.WS_THICKFRAME | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#21-Style");
1339 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#21-ExStyle");
1342 using (frm = new Form ()) {
1343 frm.MinimizeBox = !frm.MinimizeBox;
1344 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_THICKFRAME | WindowStyles.WS_SYSMENU | WindowStyles.WS_CAPTION | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#22-Style");
1345 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#22-ExStyle");
1348 using (frm = new Form ()) {
1349 frm.ShowIcon = !frm.ShowIcon;
1350 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#23-Style");
1351 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#23-ExStyle");
1354 using (frm = new Form ()) {
1355 frm.ShowInTaskbar = !frm.ShowInTaskbar;
1356 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#24-Style");
1357 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#24-ExStyle");
1361 using (frm = new Form ()) {
1362 frm.TabStop = !frm.TabStop;
1363 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#25-Style");
1364 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#25-ExStyle");
1367 using (frm = new Form ()) {
1368 frm.TopLevel = !frm.TopLevel;
1369 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_CHILD, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#26-Style");
1370 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#26-ExStyle");
1373 using (frm = new Form ()) {
1374 frm.Visible = !frm.Visible;
1375 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TILEDWINDOW | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#27-Style");
1376 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#27-ExStyle");
1379 using (frm = new Form ()) {
1380 frm.ControlBox = false;
1382 Assert.AreEqual (WindowStyles.WS_TILED | WindowStyles.WS_TABSTOP | WindowStyles.WS_GROUP | WindowStyles.WS_THICKFRAME | WindowStyles.WS_BORDER | WindowStyles.WS_CLIPCHILDREN, ((WindowStyles)TestHelper.GetCreateParams (frm).Style), "#28-Style");
1383 Assert.AreEqual (WindowExStyles.WS_EX_LEFT | WindowExStyles.WS_EX_RIGHTSCROLLBAR | WindowExStyles.WS_EX_CONTROLPARENT | WindowExStyles.WS_EX_APPWINDOW, ((WindowExStyles)TestHelper.GetCreateParams (frm).ExStyle), "#28-ExStyle");
1388 public void FormParentedTest ()
1390 using (Form frm = new Form ()) {
1391 using (Form frm2 = new Form ()) {
1392 frm2.TopLevel = false;
1393 frm.ShowInTaskbar = false;
1394 frm2.ShowInTaskbar = false;
1395 frm2.Visible = true;
1398 EventLogger log = new EventLogger (frm);
1399 EventLogger log2 = new EventLogger (frm2);
1401 frm.Controls.Add (frm2);
1403 Assert.IsTrue (log2.EventRaised ("ParentChanged"), "#C1");
1404 Assert.IsTrue (log.EventRaised ("ControlAdded"), "#P1");
1405 Assert.AreSame (frm, frm2.Parent, "#02");
1411 public void FormPropertyTest ()
1413 Form myform = new Form ();
1414 myform.Visible = true;
1415 myform.Text = "NewForm";
1416 myform.Name = "FormTest";
1417 Assert.IsNull (myform.ActiveMdiChild, "#2");
1418 Assert.IsFalse (myform.AutoScale, "#3");
1419 Assert.IsNull (myform.CancelButton, "#6");
1420 Assert.IsTrue (myform.ControlBox, "#9");
1421 Assert.IsTrue (myform.DesktopBounds.X > 0, "#10a");
1422 Assert.IsTrue (myform.DesktopBounds.Y > 0, "#10b");
1423 Assert.AreEqual (300, myform.DesktopBounds.Height, "#10c");
1424 Assert.AreEqual (300, myform.DesktopBounds.Width, "#10d");
1425 Assert.IsTrue (myform.DesktopLocation.X > 0, "#11a");
1426 Assert.IsTrue (myform.DesktopLocation.Y > 0, "#11b");
1427 Assert.AreEqual (DialogResult.None, myform.DialogResult, "#12");
1428 Assert.AreEqual (FormBorderStyle.Sizable, myform.FormBorderStyle, "#13");
1429 Assert.IsFalse (myform.HelpButton, "#14");
1430 Assert.AreEqual ("System.Drawing.Icon", myform.Icon.GetType ().ToString (), "#15");
1431 Assert.IsFalse (myform.IsMdiChild, "#16");
1432 Assert.IsFalse (myform.IsMdiContainer, "#17");
1433 Assert.IsFalse (myform.KeyPreview, "#18");
1434 Assert.IsTrue (myform.MaximizeBox, "#19");
1435 Assert.AreEqual (0, myform.MaximumSize.Height, "#20a");
1436 Assert.AreEqual (0, myform.MaximumSize.Width, "#20b");
1437 Assert.AreEqual (0, myform.MdiChildren.Length, "#21a");
1438 Assert.AreEqual (1, myform.MdiChildren.Rank, "#21b");
1439 Assert.IsFalse (myform.MdiChildren.IsSynchronized, "#21c");
1440 Assert.IsNull (myform.MdiParent, "#22");
1441 Assert.IsNull (myform.Menu, "#23");
1442 Assert.IsNull (myform.MergedMenu, "#24");
1443 Assert.IsTrue (myform.MinimizeBox, "#25");
1444 Assert.AreEqual (0, myform.MinimumSize.Height, "#26a");
1445 Assert.AreEqual (0, myform.MinimumSize.Width, "#26b");
1446 Assert.IsTrue (myform.MinimumSize.IsEmpty, "#26c");
1447 Assert.IsFalse (myform.Modal, "#27");
1448 Assert.AreEqual (1, myform.Opacity, "#28");
1449 Assert.AreEqual (0, myform.OwnedForms.Length, "#29a");
1450 Assert.AreEqual (1, myform.OwnedForms.Rank, "#29b");
1451 Assert.IsNull (myform.Owner, "#30");
1452 Assert.IsTrue (myform.ShowInTaskbar, "#31");
1453 Assert.AreEqual (300, myform.Size.Height, "#32a");
1454 Assert.AreEqual (300, myform.Size.Width, "#32b");
1455 Assert.AreEqual (SizeGripStyle.Auto, myform.SizeGripStyle, "#33");
1456 Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, myform.StartPosition, "#34");
1457 Assert.IsTrue (myform.TopLevel, "#35");
1458 Assert.IsFalse (myform.TopMost, "#36");
1459 Assert.AreEqual (Color.Empty, myform.TransparencyKey, "#37");
1460 Assert.AreEqual (FormWindowState.Normal, myform.WindowState, "#38");
1461 Assert.AreEqual (ImeMode.NoControl, myform.ImeMode, "#39");
1466 [Category ("NotWorking")]
1467 public void ActivateTest ()
1469 Form myform = new Form ();
1470 myform.ShowInTaskbar = false;
1471 myform.Visible = true;
1472 myform.Text = "NewForm";
1473 myform.Name = "FormTest";
1475 Assert.AreEqual (true, myform.Focus (), "#40");
1480 public void AddOwnedFormTest ()
1482 Form parent = new Form ();
1483 parent.ShowInTaskbar = false;
1484 parent.Text = "NewParent";
1485 Form ownedForm = new Form ();
1486 ownedForm.ShowInTaskbar = false;
1487 ownedForm.Text = "Owned Form";
1488 parent.AddOwnedForm (ownedForm);
1490 Assert.AreEqual ("NewParent", ownedForm.Owner.Text, "#41");
1491 ownedForm.Dispose ();
1495 [Test] // bug #80020
1496 public void IsHandleCreated ()
1498 Form main = new Form ();
1500 main.IsMdiContainer = true;
1501 main.ShowInTaskbar = false;
1502 Assert.IsFalse (main.IsHandleCreated, "#1");
1504 Form child = new Form ();
1505 child.MdiParent = main;
1506 child.WindowState = FormWindowState.Maximized;
1507 Assert.IsFalse (main.IsHandleCreated, "#2");
1510 Assert.IsFalse (child.IsHandleCreated, "#3");
1511 Assert.IsFalse (main.IsHandleCreated, "#4");
1514 Assert.IsTrue (child.IsHandleCreated, "#5");
1515 Assert.IsTrue (main.IsHandleCreated, "#6");
1522 public void RemoveOwnedFormTest ()
1524 Form myform = new Form ();
1525 myform.ShowInTaskbar = false;
1526 myform.Text = "NewForm";
1527 myform.Name = "FormTest";
1528 myform.RemoveOwnedForm (myform);
1530 Assert.AreEqual (null, myform.Owner, "#44");
1535 public void SetDesktopBoundsTest ()
1537 Form myform = new Form ();
1538 myform.ShowInTaskbar = false;
1539 myform.Visible = true;
1540 myform.Text = "NewForm";
1541 myform.Name = "FormTest";
1542 myform.SetDesktopBounds (10, 10, 200 , 200);
1543 Assert.AreEqual (200, myform.DesktopBounds.Height, "#45");
1548 public void SetDesktopLocationTest ()
1550 Form myform = new Form ();
1551 myform.ShowInTaskbar = false;
1552 myform.Visible = true;
1553 myform.Text = "NewForm";
1554 myform.Name = "FormTest";
1555 myform.SetDesktopLocation (10, 10);
1556 Assert.AreEqual (10, myform.DesktopLocation.X, "#46");
1561 public void SetDialogResultOutOfRange ()
1563 Form myform = new Form ();
1564 myform.ShowInTaskbar = false;
1566 myform.DialogResult = (DialogResult) (-1);
1567 Assert.Fail ("#48");
1568 } catch (InvalidEnumArgumentException) {
1572 myform.DialogResult = (DialogResult) ((int) DialogResult.No + 1);
1573 Assert.Fail ("#49");
1574 } catch (InvalidEnumArgumentException) {
1579 void myform_set_dialogresult (object sender, EventArgs e)
1581 Form f = (Form)sender;
1583 f.DialogResult = DialogResult.OK;
1586 void myform_close (object sender, EventArgs e)
1588 Form f = (Form)sender;
1594 public void SetDialogResult ()
1596 Form myform = new Form ();
1597 myform.ShowInTaskbar = false;
1598 myform.Visible = true;
1600 myform.DialogResult = DialogResult.Cancel;
1602 Assert.IsTrue (myform.Visible, "A1");
1603 Assert.IsFalse (myform.IsDisposed, "A2");
1607 Assert.IsFalse (myform.Visible, "A3");
1608 Assert.IsTrue (myform.IsDisposed, "A4");
1610 DialogResult result;
1612 myform = new Form ();
1613 myform.ShowInTaskbar = false;
1614 myform.VisibleChanged += new EventHandler (myform_set_dialogresult);
1615 result = myform.ShowDialog ();
1617 Assert.AreEqual (result, DialogResult.OK, "A5");
1618 Assert.IsFalse (myform.Visible, "A6");
1619 Assert.IsFalse (myform.IsDisposed, "A7");
1622 myform = new Form ();
1623 myform.ShowInTaskbar = false;
1624 myform.VisibleChanged += new EventHandler (myform_close);
1625 result = myform.ShowDialog ();
1627 Assert.AreEqual (result, DialogResult.Cancel, "A8");
1628 Assert.IsFalse (myform.Visible, "A9");
1629 Assert.IsFalse (myform.IsDisposed, "A10");
1635 public void ShowDialog_Child ()
1637 Form main = new Form ();
1638 main.IsMdiContainer = true;
1639 Form child = new Form ();
1640 child.MdiParent = main;
1642 child.ShowDialog ();
1644 } catch (InvalidOperationException ex) {
1645 // Forms that are not top level forms cannot be displayed as a
1646 // modal dialog. Remove the form from any parent form before
1647 // calling ShowDialog.
1648 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1649 Assert.IsNull (ex.InnerException, "#3");
1650 Assert.IsNotNull (ex.Message, "#4");
1652 Assert.IsNull (child.Owner, "#5");
1658 public void ShowDialog_Disabled ()
1660 Form form = new Form ();
1661 form.Enabled = false;
1664 Assert.Fail ("#A1");
1665 } catch (InvalidOperationException ex) {
1666 // Forms that are not enabled cannot be displayed as a modal
1667 // dialog. Set the form's enabled property to true before
1668 // calling ShowDialog.
1669 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1670 Assert.IsNull (ex.InnerException, "#A3");
1671 Assert.IsNotNull (ex.Message, "#A4");
1673 Assert.IsNull (form.Owner, "#A5");
1676 Form main = new Form ();
1679 form.Enabled = false;
1682 Assert.Fail ("#B1");
1683 } catch (InvalidOperationException) {
1685 Assert.IsNotNull (form.Owner, "#B2");
1686 Assert.AreSame (main, form.Owner, "#B3");
1692 [Category ("NotWorking")]
1693 public void ShowDialog_Owner_Circular ()
1695 Form main = new Form ();
1696 Form child = new Form ();
1699 main.ShowDialog (child);
1701 } catch (ArgumentException ex) {
1702 // A circular control reference has been made. A control cannot
1703 // be owned or parented to itself
1704 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1705 Assert.IsNull (ex.InnerException, "#3");
1706 Assert.IsNotNull (ex.Message, "#4");
1707 Assert.IsNull (ex.ParamName, "#5");
1709 Assert.IsNull (main.Owner, "#6");
1714 [Test] // bug #80773
1715 public void ShowDialog_Owner_Self ()
1717 Form form = new Form ();
1719 form.ShowDialog (form);
1720 Assert.Fail ("#A1");
1721 } catch (ArgumentException ex) {
1722 // Forms cannot own themselves or their owners
1723 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1724 Assert.IsNull (ex.InnerException, "#A3");
1725 Assert.IsNotNull (ex.Message, "#A4");
1726 Assert.IsNotNull (ex.ParamName, "#A5");
1727 Assert.AreEqual ("owner", ex.ParamName, "#A6");
1729 Assert.IsNull (form.Owner, "#A7");
1732 Form main = new Form ();
1736 form.ShowDialog (form);
1737 Assert.Fail ("#B1");
1738 } catch (ArgumentException) {
1740 Assert.IsNotNull (form.Owner);
1741 Assert.AreSame (main, form.Owner, "#B2");
1747 public void ShowDialog_Visible ()
1749 Form form = new Form ();
1750 form.ShowInTaskbar = false;
1751 form.Visible = true;
1754 Assert.Fail ("#A1");
1755 } catch (InvalidOperationException ex) {
1756 // Forms that are already visible cannot be displayed as a modal
1757 // dialog. Set the form's visible property to false before
1758 // calling ShowDialog.
1759 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1760 Assert.IsNull (ex.InnerException, "#A3");
1761 Assert.IsNotNull (ex.Message, "#A4");
1763 Assert.IsNull (form.Owner, "#A5");
1766 Form main = new Form ();
1769 form.Visible = true;
1772 Assert.Fail ("#B1");
1773 } catch (InvalidOperationException) {
1775 Assert.IsNotNull (form.Owner, "#B2");
1776 Assert.AreSame (main, form.Owner, "#B3");
1781 [Test] // bug #80604
1782 public void VisibleOnLoad ()
1784 MockForm form = new MockForm ();
1785 form.CloseOnLoad = true;
1786 Application.Run (form);
1787 Assert.IsTrue (form.VisibleOnLoad, "#1");
1790 form = new MockForm ();
1791 form.ShowInTaskbar = false;
1793 Assert.IsTrue (form.VisibleOnLoad, "#2");
1797 [Test] // bug #80052
1798 [Category ("NotWorking")]
1799 public void Location ()
1805 Form formA = new Form ();
1806 formA.ShowInTaskbar = false;
1807 formA.StartPosition = FormStartPosition.CenterParent;
1808 formA.Location = new Point (151, 251);
1811 Assert.AreEqual (FormStartPosition.CenterParent, formA.StartPosition, "#A1");
1812 Assert.IsFalse (formA.Location.X == 151, "#A2");
1813 Assert.IsFalse (formA.Location.Y == 251, "#A3");
1815 formA.Location = new Point (311, 221);
1817 Assert.AreEqual (FormStartPosition.CenterParent, formA.StartPosition, "#A4");
1818 Assert.AreEqual (311, formA.Location.X, "#A5");
1819 Assert.AreEqual (221, formA.Location.Y, "#A6");
1827 Form formB = new Form ();
1828 formB.ShowInTaskbar = false;
1829 formB.StartPosition = FormStartPosition.CenterScreen;
1830 formB.Location = new Point (151, 251);
1833 Assert.AreEqual (FormStartPosition.CenterScreen, formB.StartPosition, "#B1");
1834 Assert.IsFalse (formB.Location.X == 151, "#B2");
1835 Assert.IsFalse (formB.Location.Y == 251, "#B3");
1837 formB.Location = new Point (311, 221);
1839 Assert.AreEqual (FormStartPosition.CenterScreen, formB.StartPosition, "#B4");
1840 Assert.AreEqual (311, formB.Location.X, "#B5");
1841 Assert.AreEqual (221, formB.Location.Y, "#B6");
1849 Form formC = new Form ();
1850 formC.ShowInTaskbar = false;
1851 formC.StartPosition = FormStartPosition.Manual;
1852 formC.Location = new Point (151, 251);
1855 Assert.AreEqual (FormStartPosition.Manual, formC.StartPosition, "#C1");
1856 Assert.AreEqual (151, formC.Location.X, "#C2");
1857 Assert.AreEqual (251, formC.Location.Y, "#C3");
1859 formC.Location = new Point (311, 221);
1861 Assert.AreEqual (FormStartPosition.Manual, formC.StartPosition, "#C4");
1862 Assert.AreEqual (311, formC.Location.X, "#C5");
1863 Assert.AreEqual (221, formC.Location.Y, "#C6");
1868 // WindowsDefaultBounds
1871 Form formD = new Form ();
1872 formD.ShowInTaskbar = false;
1873 formD.StartPosition = FormStartPosition.WindowsDefaultBounds;
1874 formD.Location = new Point (151, 251);
1877 Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, formD.StartPosition, "#D1");
1878 Assert.IsFalse (formD.Location.X == 151, "#D2");
1879 Assert.IsFalse (formD.Location.Y == 251, "#D3");
1881 formD.Location = new Point (311, 221);
1883 Assert.AreEqual (FormStartPosition.WindowsDefaultBounds, formD.StartPosition, "#D4");
1884 Assert.AreEqual (311, formD.Location.X, "#D5");
1885 Assert.AreEqual (221, formD.Location.Y, "#D6");
1890 // WindowsDefaultLocation
1893 Form formE = new Form ();
1894 formE.ShowInTaskbar = false;
1895 formE.Location = new Point (151, 251);
1898 Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, formE.StartPosition, "#E1");
1899 Assert.IsFalse (formE.Location.X == 151, "#E2");
1900 Assert.IsFalse (formE.Location.Y == 251, "#E3");
1902 formE.Location = new Point (311, 221);
1904 Assert.AreEqual (FormStartPosition.WindowsDefaultLocation, formE.StartPosition, "#E4");
1905 Assert.AreEqual (311, formE.Location.X, "#E5");
1906 Assert.AreEqual (221, formE.Location.Y, "#E6");
1912 public void Opacity ()
1915 using (frm = new Form ()) {
1916 Assert.AreEqual (1.0f, frm.Opacity, "#01-opacity");
1918 Assert.AreEqual (0.50f, frm.Opacity, "#02-opacity");
1919 frm.Opacity = -0.1f;
1920 Assert.AreEqual (0, frm.Opacity, "#03-opacity");
1922 Assert.AreEqual (1, frm.Opacity, "#04-opacity");
1927 public void DisposeOwnerTest ()
1929 Form f1 = new Form ();
1930 Form f2 = new Form ();
1936 Assert.IsNull (f2.Owner, "1");
1937 Assert.AreEqual (0, f1.OwnedForms.Length, "2");
1941 [ExpectedException (typeof (ObjectDisposedException))]
1942 public void AccessDisposedForm ()
1944 Form myform = new Form ();
1945 myform.ShowInTaskbar = false;
1948 myform.Close (); // this should result in the form being disposed
1949 myform.Show (); // and this line should result in the ODE being thrown
1954 public void DoDestroyHandle ()
1958 public void DoRecreateHandle ()
1964 int handle_destroyed_count;
1965 void handle_destroyed (object sender, EventArgs e)
1967 handle_destroyed_count++;
1971 public void DestroyHandleTest ()
1973 handle_destroyed_count = 0;
1975 MyForm f1 = new MyForm ();
1976 f1.HandleDestroyed += new EventHandler (handle_destroyed);
1978 f1.DoDestroyHandle ();
1979 Assert.AreEqual (1, handle_destroyed_count, "1");
1981 MyForm f2 = new MyForm ();
1982 f2.HandleDestroyed += new EventHandler (handle_destroyed);
1984 f2.DoRecreateHandle ();
1985 Assert.AreEqual (2, handle_destroyed_count, "2");
1992 public void FormClose ()
1994 Form myform = new Form ();
1995 myform.ShowInTaskbar = false;
1997 Assert.IsFalse (myform.Visible, "A1");
1998 Assert.IsFalse (myform.IsDisposed, "A2");
2002 Assert.IsFalse (myform.Visible, "A3");
2003 Assert.IsFalse (myform.IsDisposed, "A4");
2007 Assert.IsTrue (myform.Visible, "A5");
2008 Assert.IsFalse (myform.IsDisposed, "A6");
2012 Assert.IsFalse (myform.Visible, "A7");
2013 Assert.IsTrue (myform.IsDisposed, "A8");
2017 public void FormClose2 ()
2019 WMCloseWatcher f = new WMCloseWatcher ();
2020 f.ShowInTaskbar = false;
2023 Assert.IsFalse (f.Visible, "A1");
2025 Assert.AreEqual (0, f.close_count, "A2");
2030 Assert.AreEqual (1, f.close_count, "A3");
2033 class WMCloseWatcher : Form {
2034 public int close_count;
2036 protected override void WndProc (ref Message msg) {
2037 if (msg.Msg == 0x0010 /* WM_CLOSE */) {
2041 base.WndProc (ref msg);
2045 class SwallowOnActivated : Form {
2046 protected override void OnActivated (EventArgs e)
2051 protected override void OnCreateControl () {
2052 base.OnCreateControl ();
2056 class EnterTest : Button {
2057 protected override void OnEnter (EventArgs e)
2063 public bool on_enter;
2067 public void OnActivateEventHandlingTest1 ()
2069 if (TestHelper.RunningOnUnix) {
2070 Assert.Ignore ("Relies on form.Show() synchronously generating WM_ACTIVATE");
2073 SwallowOnActivated f = new SwallowOnActivated ();
2075 f.ShowInTaskbar = false;
2077 EnterTest c = new EnterTest ();
2082 Assert.IsTrue (c.on_enter, "1");
2089 public void FormClosingEvents ()
2092 Form f = new Form ();
2093 string events = string.Empty;
2095 f.Closing += new CancelEventHandler (delegate (Object obj, CancelEventArgs e) { events += ("Closing;"); });
2096 f.FormClosing += new FormClosingEventHandler (delegate (Object obj, FormClosingEventArgs e) { events += string.Format ("FormClosing [Reason:{0} - Cancel:{1}]", e.CloseReason, e.Cancel); });
2101 Assert.AreEqual ("Closing;FormClosing [Reason:UserClosing - Cancel:False]", events, "A1");
2105 public void FormClosingEventsCancel ()
2107 // Shows that setting Cancel in Closing flows through to FormClosing
2108 Form f = new Form ();
2109 string events = string.Empty;
2111 f.Closing += new CancelEventHandler (delegate (Object obj, CancelEventArgs e) { events += ("Closing;"); e.Cancel = true; });
2112 f.FormClosing += new FormClosingEventHandler (delegate (Object obj, FormClosingEventArgs e) { events += string.Format("FormClosing [Reason:{0} - Cancel:{1}]", e.CloseReason, e.Cancel); e.Cancel = false; });
2117 Assert.AreEqual ("Closing;FormClosing [Reason:UserClosing - Cancel:True]", events, "A1");
2121 public void FormClosedEvents ()
2124 Form f = new Form ();
2125 string events = string.Empty;
2127 f.Closed += new EventHandler (delegate (Object obj, EventArgs e) { events += ("Closed;"); });
2128 f.FormClosed += new FormClosedEventHandler (delegate (Object obj, FormClosedEventArgs e) { events += string.Format ("FormClosed [Reason:{0}]", e.CloseReason); });
2133 Assert.AreEqual ("Closed;FormClosed [Reason:UserClosing]", events, "A1");
2137 public void ShowWithOwner ()
2139 Form f = new Form ();
2140 Button b = new Button ();
2143 Form f2 = new Form ();
2147 Assert.AreSame (f, f2.Owner, "A1");
2153 Assert.AreSame (f, f2.Owner, "A2");
2156 Button b2 = new Button ();
2160 Assert.AreEqual (null, f2.Owner, "A3");
2165 Assert.AreEqual (null, f2.Owner, "A4");
2172 [ExpectedException (typeof (InvalidOperationException))]
2173 public void ShowWithOwnerIOE ()
2175 using (Form f = new Form ()) {
2180 [Test] // Bug #79959, #80574, #80791
2181 [Category ("NotWorking")]
2182 public void BehaviorResizeOnBorderStyleChanged ()
2184 // Marked NotWorking because the ClientSize is dependent on the WM.
2185 // The values below match XP Luna to make sure our behavior is the same.
2186 Form f = new Form ();
2187 f.ShowInTaskbar = false;
2190 Assert.AreEqual (true, f.IsHandleCreated, "A0");
2192 Assert.AreEqual (new Size (300, 300), f.Size, "A1");
2193 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A2");
2195 f.FormBorderStyle = FormBorderStyle.Fixed3D;
2196 Assert.AreEqual (new Size (302, 302), f.Size, "A3");
2197 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4");
2199 f.FormBorderStyle = FormBorderStyle.FixedDialog;
2200 Assert.AreEqual (new Size (298, 298), f.Size, "A5");
2201 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A6");
2203 f.FormBorderStyle = FormBorderStyle.FixedSingle;
2204 Assert.AreEqual (new Size (298, 298), f.Size, "A7");
2205 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A8");
2207 f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
2208 Assert.AreEqual (new Size (298, 290), f.Size, "A9");
2209 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A0");
2211 f.FormBorderStyle = FormBorderStyle.None;
2212 Assert.AreEqual (new Size (292, 266), f.Size, "A11");
2213 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A12");
2215 f.FormBorderStyle = FormBorderStyle.SizableToolWindow;
2216 Assert.AreEqual (new Size (300, 292), f.Size, "A13");
2217 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A14");
2219 f.FormBorderStyle = FormBorderStyle.Sizable;
2220 Assert.AreEqual (new Size (300, 300), f.Size, "A15");
2221 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A16");
2226 [Test] // Bug #80574, #80791
2227 [Category ("NotWorking")]
2228 public void BehaviorResizeOnBorderStyleChangedNotVisible ()
2230 // Marked NotWorking because the ClientSize is dependent on the WM.
2231 // The values below match XP Luna to make sure our behavior is the same.
2232 Form f = new Form ();
2233 f.ShowInTaskbar = false;
2235 Assert.AreEqual (false, f.IsHandleCreated, "A0");
2237 Assert.AreEqual (new Size (300, 300), f.Size, "A1");
2238 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A2");
2240 f.FormBorderStyle = FormBorderStyle.Fixed3D;
2241 Assert.AreEqual (new Size (300, 300), f.Size, "A3");
2242 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4");
2244 f.FormBorderStyle = FormBorderStyle.FixedDialog;
2245 Assert.AreEqual (new Size (300, 300), f.Size, "A5");
2246 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A6");
2248 f.FormBorderStyle = FormBorderStyle.FixedSingle;
2249 Assert.AreEqual (new Size (300, 300), f.Size, "A7");
2250 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A8");
2252 f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
2253 Assert.AreEqual (new Size (300, 300), f.Size, "A9");
2254 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A0");
2256 f.FormBorderStyle = FormBorderStyle.None;
2257 Assert.AreEqual (new Size (300, 300), f.Size, "A11");
2258 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A12");
2260 f.FormBorderStyle = FormBorderStyle.SizableToolWindow;
2261 Assert.AreEqual (new Size (300, 300), f.Size, "A13");
2262 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A14");
2264 f.FormBorderStyle = FormBorderStyle.Sizable;
2265 Assert.AreEqual (new Size (300, 300), f.Size, "A15");
2266 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A16");
2269 [Test] // Bug #80574, #80791
2270 [Category ("NotWorking")]
2271 public void MoreBehaviorResizeOnBorderStyleChangedNotVisible ()
2273 // Marked NotWorking because the ClientSize is dependent on the WM.
2274 // The values below match XP Luna to make sure our behavior is the same.
2275 Form f = new Form ();
2276 f.ShowInTaskbar = false;
2281 Assert.AreEqual (true, f.IsHandleCreated, "A0");
2283 f.FormBorderStyle = FormBorderStyle.Sizable;
2284 Assert.AreEqual (new Size (300, 300), f.Size, "A1");
2285 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A2");
2286 f.FormBorderStyle = FormBorderStyle.None;
2287 Assert.AreEqual (new Size (292, 266), f.Size, "A3");
2288 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4");
2292 [Test] // Bug #81582
2293 [Category ("NotWorking")]
2294 public void GotFocusWithoutCallingOnLoadBase ()
2296 NoOnLoadBaseForm f = new NoOnLoadBaseForm ();
2298 Assert.AreEqual (true, f.got_focus_called, "H1");
2302 private class NoOnLoadBaseForm : Form
2304 public bool got_focus_called = false;
2306 public NoOnLoadBaseForm ()
2308 TreeView tv = new TreeView ();
2309 tv.GotFocus += new EventHandler (tv_GotFocus);
2313 void tv_GotFocus (object sender, EventArgs e)
2315 got_focus_called = true;
2318 protected override void OnLoad (EventArgs e)
2323 [Test] // bug #339641
2324 public void ChildFocused ()
2326 if (TestHelper.RunningOnUnix) {
2327 Assert.Ignore ("Relies on form.Show() synchronously generating WM_ACTIVATE");
2329 using (Form f = new TimeBombedForm ()) {
2330 TreeView tv = new TreeView ();
2331 EventLogger log = new EventLogger (tv);
2332 tv.GotFocus += new EventHandler (tv_GotFocus);
2333 f.Activated += new EventHandler (f_Activated);
2334 f.Controls.Add (tv);
2336 Assert.IsTrue (log.EventRaised ("GotFocus"), "#01");
2340 void f_Activated (object sender, EventArgs e)
2342 //Console.WriteLine (" ACTIVATED");
2343 //Console.WriteLine (Environment.StackTrace);
2346 void tv_GotFocus (object sender, EventArgs e)
2348 //Console.WriteLine (Environment.StackTrace);
2351 [Test] // bug #80773
2352 public void DontSetOwnerOnShowDialogException ()
2354 Form f = new Form ();
2355 f.ShowInTaskbar = false;
2357 try { f.ShowDialog (f); }
2360 Assert.AreEqual (null, f.Owner, "H1");
2366 public void MinimumWindowSize ()
2368 Form f = new Form ();
2369 f.ShowInTaskbar = false;
2372 f.Size = new Size (0, 0);
2373 Assert.AreEqual (SystemInformation.MinimumWindowSize, f.Size);
2379 public void Bug82470 ()
2381 Form f = new Form ();
2382 f.Load += new EventHandler (Form_LoadAndHide);
2385 Assert.AreEqual (true, f.Visible, "A1");
2390 private void Form_LoadAndHide (object sender, EventArgs e)
2392 ((Form)sender).Visible = false;
2397 public void AutoSizeGrowOnly ()
2399 Form f = new Form ();
2400 f.ShowInTaskbar = false;
2403 Button b = new Button ();
2404 b.Size = new Size (200, 200);
2405 b.Location = new Point (200, 200);
2410 Assert.AreEqual (new Size (403, 403), f.ClientSize, "A1");
2412 f.Controls.Remove (b);
2413 Assert.AreEqual (new Size (403, 403), f.ClientSize, "A2");
2419 public void AutoSizeReset ()
2421 Form f = new Form ();
2422 f.ShowInTaskbar = false;
2424 Button b = new Button ();
2425 b.Size = new Size (200, 200);
2426 b.Location = new Point (200, 200);
2431 Size start_size = f.ClientSize;
2434 Assert.AreEqual (new Size (403, 403), f.ClientSize, "A1");
2437 Assert.AreEqual (start_size, f.ClientSize, "A2");
2442 public void AutoSizeGrowAndShrink ()
2444 Form f = new Form ();
2445 f.ShowInTaskbar = false;
2447 f.AutoSizeMode = AutoSizeMode.GrowAndShrink;
2451 // Make sure form shrunk
2452 Assert.IsTrue (f.ClientSize.Width < 150, "A1");
2453 Assert.IsTrue (f.ClientSize.Height < 150, "A1-2");
2455 Button b = new Button ();
2456 b.Size = new Size (200, 200);
2457 b.Location = new Point (0, 0);
2460 Assert.AreEqual (new Size (203, 203), f.ClientSize, "A2");
2465 public void GetScaledBoundsTest ()
2467 if (TestHelper.RunningOnUnix)
2468 Assert.Ignore ("Depends on WM decoration sizes, values correspond to windows");
2470 ScaleForm c = new ScaleForm ();
2472 Rectangle r = new Rectangle (100, 200, 300, 400);
2474 Assert.AreEqual (new Rectangle (100, 200, 584, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A1");
2475 Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A2");
2476 Assert.AreEqual (new Rectangle (100, 200, 584, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A3");
2477 Assert.AreEqual (new Rectangle (100, 200, 300, 218), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A4");
2478 Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A5");
2479 Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A6");
2481 Assert.AreEqual (new Rectangle (100, 200, 300, 400), c.PublicGetScaledBounds (r, new SizeF (1f, 1f), BoundsSpecified.All), "A6-2");
2482 Assert.AreEqual (new Rectangle (100, 200, 584, 764), c.PublicGetScaledBounds (r, new SizeF (2f, 2f), BoundsSpecified.All), "A7");
2483 Assert.AreEqual (new Rectangle (100, 200, 868, 1128), c.PublicGetScaledBounds (r, new SizeF (3f, 3f), BoundsSpecified.All), "A8");
2484 Assert.AreEqual (new Rectangle (100, 200, 1152, 1492), c.PublicGetScaledBounds (r, new SizeF (4f, 4f), BoundsSpecified.All), "A9");
2485 Assert.AreEqual (new Rectangle (100, 200, 158, 218), c.PublicGetScaledBounds (r, new SizeF (.5f, .5f), BoundsSpecified.All), "A10");
2489 public void MethodScaleControl ()
2491 if (TestHelper.RunningOnUnix)
2492 Assert.Ignore ("Depends on WM decoration sizes, values correspond to windows");
2494 ScaleForm f = new ScaleForm ();
2495 f.Location = new Point (5, 10);
2497 Assert.AreEqual (new Rectangle (5, 10, 300, 300), f.Bounds, "A1");
2499 f.PublicScaleControl (new SizeF (2.0f, 2.0f), BoundsSpecified.All);
2500 Assert.AreEqual (new Rectangle (5, 10, 584, 564), f.Bounds, "A2");
2502 f.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Location);
2503 Assert.AreEqual (new Rectangle (5, 10, 584, 564), f.Bounds, "A3");
2505 f.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Size);
2506 Assert.AreEqual (new Rectangle (5, 10, 300, 300), f.Bounds, "A4");
2508 f.PublicScaleControl (new SizeF (2.5f, 2.5f), BoundsSpecified.Size);
2509 Assert.AreEqual (new Rectangle (5, 10, 726, 696), f.Bounds, "A5");
2511 f.PublicScaleControl (new SizeF (.3f, .3f), BoundsSpecified.Size);
2512 Assert.AreEqual (new Rectangle (5, 10, 229, 234), f.Bounds, "A6");
2517 private class ScaleForm : Form
2519 public Rectangle PublicGetScaledBounds (Rectangle bounds, SizeF factor, BoundsSpecified specified)
2521 return base.GetScaledBounds (bounds, factor, specified);
2524 public void PublicScaleControl (SizeF factor, BoundsSpecified specified)
2526 base.ScaleControl (factor, specified);
2531 public void Bug325436 ()
2533 Form f = new Form ();
2534 f.ShowInTaskbar = false;
2535 f.ClientSize = new Size (320, 40);
2536 f.ControlBox = false;
2537 f.FormBorderStyle = FormBorderStyle.None;
2538 f.MaximizeBox = false;
2539 f.MinimizeBox = false;
2542 Assert.AreEqual (new Size (320, 40), f.ClientSize, "A1");
2546 f.ShowInTaskbar = false;
2547 f.ControlBox = false;
2548 f.FormBorderStyle = FormBorderStyle.None;
2549 f.MaximizeBox = false;
2550 f.MinimizeBox = false;
2551 f.ClientSize = new Size(320, 40);
2554 Assert.AreEqual (new Size (320, 40), f.ClientSize, "A2");
2559 #region PreferredSize
2561 public void PreferredSize ()
2563 PreferredSizeForm form = new PreferredSizeForm ();
2564 form.AutoSize = true;
2565 Control control = new Control ();
2566 form.Controls.Add (control);
2567 control.Size = new Size (500, 500);
2569 form.Controls.Clear ();
2574 private class PreferredSizeForm : Form
2578 Assert.AreEqual (SizeFromClientSize (new Size (503, 503)), PreferredSize, "1");
2581 public void Test2 ()
2583 Assert.AreEqual (SizeFromClientSize (new Size (0, 0)), PreferredSize, "1");
2588 private class MockForm : Form
2590 public bool CloseOnLoad {
2591 get { return _closeOnLoad; }
2592 set { _closeOnLoad = value; }
2595 public bool VisibleOnLoad {
2596 get { return _visibleOnLoad; }
2599 protected override void OnLoad(EventArgs e) {
2601 _visibleOnLoad = Visible;
2606 private bool _closeOnLoad;
2607 private bool _visibleOnLoad;
2610 private class MockButton : Button
2612 public MockButton (bool notify)
2617 public bool Notify {
2618 get { return _notify; }
2619 set { _notify = value; }
2622 public bool IsDefaultButton
2624 get { return base.IsDefault; }
2625 set { base.IsDefault = value; }
2628 public override void NotifyDefault (bool value)
2631 base.NotifyDefault (value);
2634 private bool _notify;
2637 private class ButtonControl : IButtonControl
2639 public DialogResult DialogResult {
2640 get { return _dialogResult; }
2641 set { _dialogResult = value; }
2644 public bool IsDefaultButton {
2645 get { return _isDefault; }
2648 public void NotifyDefault (bool value)
2653 public void PerformClick ()
2657 private bool _isDefault;
2658 private DialogResult _dialogResult = DialogResult.None;
2663 public void RestoreBounds ()
2665 Form f = new Form ();
2668 Assert.AreEqual (new Size (300, 300), f.RestoreBounds.Size, "A1");
2671 f.Location = new Point (0, 0);
2672 Assert.AreEqual (new Rectangle (0, 0, 300, 300), f.RestoreBounds, "A2");
2675 f.Size = new Size (250, 250);
2676 Assert.AreEqual (new Rectangle (0, 0, 250, 250), f.RestoreBounds, "A3");
2678 // Minimize the form
2679 f.WindowState = FormWindowState.Minimized;
2680 Assert.AreEqual (new Rectangle (0, 0, 250, 250), f.RestoreBounds, "A4");
2682 // Move the form (while minimized)
2683 f.Location = new Point (10, 10);
2684 Assert.AreEqual (new Rectangle (10, 10, 250, 250), f.RestoreBounds, "A5");
2686 // Resize the form (while minimized)
2687 f.Size = new Size (275, 275);
2688 Assert.AreEqual (new Rectangle (10, 10, 275, 275), f.RestoreBounds, "A6");
2690 // Maximize the form
2691 f.WindowState = FormWindowState.Maximized;
2692 Assert.AreEqual (new Rectangle (10, 10, 275, 275), f.RestoreBounds, "A7");
2694 // Move the form (while maximized)
2695 f.Location = new Point (20, 20);
2696 Assert.AreEqual (new Rectangle (20, 20, 275, 275), f.RestoreBounds, "A8");
2698 // Resize the form (while maximized)
2699 f.Size = new Size (285, 285);
2700 Assert.AreEqual (new Rectangle (20, 20, 285, 285), f.RestoreBounds, "A9");
2705 [Test] // Bug 353827
2706 public void AutoScaleModeTest ()
2708 Form f = new Form ();
2710 // AutoScale starts off true
2711 Assert.AreEqual (true, f.AutoScale, "A1");
2713 // Setting AutoScaleMode turns AutoScale off
2714 f.AutoScaleMode = AutoScaleMode.Font;
2715 Assert.AreEqual (false, f.AutoScale, "A2");
2716 Assert.AreEqual (AutoScaleMode.Font, f.AutoScaleMode, "A3");
2718 // Changing Font resets AutoScaleBaseSize..
2719 f.Font = new Font ("Arial", 10);
2720 Assert.AreEqual (RoundSizeF (Form.GetAutoScaleSize (f.Font)), f.AutoScaleBaseSize, "A4");
2722 f.Font = new Font ("Arial", 12);
2723 Assert.AreEqual (RoundSizeF (Form.GetAutoScaleSize (f.Font)), f.AutoScaleBaseSize, "A5");
2725 // ..Until AutoScaleBaseSize is explicitly set
2726 f.AutoScaleBaseSize = new Size (5, 13);
2727 Assert.AreEqual (new Size (5, 13), f.AutoScaleBaseSize, "A6");
2729 f.Font = new Font ("Arial", 14F);
2730 Assert.IsTrue (RoundSizeF (Form.GetAutoScaleSize (f.Font)) != f.AutoScaleBaseSize, "A5");
2735 private Size RoundSizeF (SizeF sizef)
2737 return new Size ((int)Math.Round (sizef.Width), (int)Math.Round (sizef.Height));
2740 [Test] // Bug 354669
2741 public void AutoScaleDetails ()
2743 ProtectedForm f = new ProtectedForm ();
2748 // First AutoScaleMode shouldn't reset AutoScaleDimensions
2749 f.AutoScaleDimensions = new SizeF (3F, 3F);
2750 f.AutoScaleMode = AutoScaleMode.Font;
2751 Assert.AreEqual (new SizeF (3F, 3F), f.AutoScaleDimensions, "A1");
2753 // Subsequent calls will reset it to 0, 0
2754 f.AutoScaleMode = AutoScaleMode.Dpi;
2755 Assert.AreEqual (SizeF.Empty, f.AutoScaleDimensions, "A2");
2759 // CurrentAutoScaleDimensions should be nonzero
2760 Assert.IsFalse (f.CurrentAutoScaleDimensions == SizeF.Empty, "A3");
2762 // AutoScaleDimensions and CurrentAutoScaleDimensions should match after ResumeLayout
2763 Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A4");
2765 // CurrentAutoScaleDimensions should match AutoScaleDimensions for AutoScaleMode.None
2767 f.AutoScaleMode = AutoScaleMode.None;
2768 f.AutoScaleDimensions = new SizeF (5F, 5F);
2770 Assert.AreEqual (new SizeF (5F, 5F), f.AutoScaleDimensions, "A5");
2771 Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A6");
2773 // ResumeLayout changes nothing
2776 Assert.AreEqual (new SizeF (5F, 5F), f.AutoScaleDimensions, "A7");
2777 Assert.AreEqual (f.AutoScaleDimensions, f.CurrentAutoScaleDimensions, "A8");
2779 // AutoScaleFactor should be ~2,2 if PerformAutoScale hasn't run
2780 f.ClientSize = new Size (150, 150);
2782 f.AutoScaleMode = AutoScaleMode.Dpi;
2783 f.AutoScaleDimensions = new SizeF (f.CurrentAutoScaleDimensions.Width / 2F, f.CurrentAutoScaleDimensions.Height / 2F);
2784 f.ClientSize = new Size (200, 200);
2786 Assert.AreEqual (new Size (2, 2), RoundSizeF (f.GetPublicAutoScaleFactor ()), "A9");
2788 // AutoScaleFactor should be 1 after ResumeLayout
2791 Assert.AreEqual (new SizeF (1F, 1F), f.GetPublicAutoScaleFactor (), "A10");
2792 Assert.AreEqual (new Size (400, 400), f.ClientSize, "A11");
2794 // PerformAutoScale happens immediately when layout not suspended
2795 f.ClientSize = new Size (125, 125);
2796 f.AutoScaleDimensions = new SizeF (f.CurrentAutoScaleDimensions.Width / 2F, f.CurrentAutoScaleDimensions.Height / 2F);
2797 Assert.AreEqual (new Size (250, 250), f.ClientSize, "A12");
2802 private class ProtectedForm : Form
2804 public SizeF GetPublicAutoScaleFactor ()
2806 return AutoScaleFactor;
2812 public class TimeBombedForm : Form
2815 public bool CloseOnPaint;
2816 public string Reason;
2817 public TimeBombedForm ()
2819 timer = new Timer ();
2820 timer.Interval = 500;
2821 timer.Tick += new EventHandler (timer_Tick);
2825 void timer_Tick (object sender, EventArgs e)
2831 protected override void OnPaint (PaintEventArgs pevent)
2833 base.OnPaint (pevent);