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
;
16 using NUnit
.Framework
;
18 using CategoryAttribute
= NUnit
.Framework
.CategoryAttribute
;
20 namespace MonoTests
.System
.Windows
.Forms
27 [Category ("NotWorking")]
28 public void FormStartupPositionChangeTest ()
30 using (Form frm
= new Form ())
32 frm
.ShowInTaskbar
= false;
33 frm
.StartPosition
= FormStartPosition
.Manual
;
34 frm
.Location
= new Point (0, 0);
37 // On X there seem to be pending messages in the queue aren't processed
38 // before Show returns, so process them. Otherwise the Location returns
39 // something like (5,23)
40 Application
.DoEvents ();
42 Assert
.AreEqual ("{X=0,Y=0}", frm
.Location
.ToString (), "#01");
44 frm
.StartPosition
= FormStartPosition
.CenterParent
;
45 Assert
.AreEqual ("{X=0,Y=0}", frm
.Location
.ToString (), "#02");
47 frm
.StartPosition
= FormStartPosition
.CenterScreen
;
48 Assert
.AreEqual ("{X=0,Y=0}", frm
.Location
.ToString (), "#03");
50 frm
.StartPosition
= FormStartPosition
.Manual
;
51 Assert
.AreEqual ("{X=0,Y=0}", frm
.Location
.ToString (), "#04");
53 frm
.StartPosition
= FormStartPosition
.WindowsDefaultBounds
;
54 Assert
.AreEqual ("{X=0,Y=0}", frm
.Location
.ToString (), "#05");
56 frm
.StartPosition
= FormStartPosition
.WindowsDefaultLocation
;
57 Assert
.AreEqual ("{X=0,Y=0}", frm
.Location
.ToString (), "#06");
62 public void FormStartupPositionTest ()
66 using (Form frm
= new Form ())
68 cp
= TestHelper
.GetCreateParams (frm
);
69 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, frm
.StartPosition
, "$01");
70 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#01");
72 frm
.StartPosition
= FormStartPosition
.CenterParent
;
73 cp
= TestHelper
.GetCreateParams (frm
);
74 Assert
.AreEqual (FormStartPosition
.CenterParent
, frm
.StartPosition
, "$01");
75 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#02");
77 frm
.StartPosition
= FormStartPosition
.CenterScreen
;
78 cp
= TestHelper
.GetCreateParams (frm
);
79 Assert
.AreEqual (FormStartPosition
.CenterScreen
, frm
.StartPosition
, "$01");
80 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");
82 frm
.StartPosition
= FormStartPosition
.Manual
;
83 cp
= TestHelper
.GetCreateParams (frm
);
84 Assert
.AreEqual (FormStartPosition
.Manual
, frm
.StartPosition
, "$01");
85 Assert
.AreEqual (new Point (0, 0).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#04");
87 frm
.StartPosition
= FormStartPosition
.WindowsDefaultBounds
;
88 cp
= TestHelper
.GetCreateParams (frm
);
89 Assert
.AreEqual (FormStartPosition
.WindowsDefaultBounds
, frm
.StartPosition
, "$01");
90 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#05");
92 frm
.StartPosition
= FormStartPosition
.WindowsDefaultLocation
;
93 cp
= TestHelper
.GetCreateParams (frm
);
94 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, frm
.StartPosition
, "$01");
95 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#06");
100 using (Form frm
= new Form ()) {
101 frm
.Location
= new Point (23, 45);
103 cp
= TestHelper
.GetCreateParams (frm
);
104 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, frm
.StartPosition
, "$A1");
105 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#A1");
107 frm
.StartPosition
= FormStartPosition
.CenterParent
;
108 cp
= TestHelper
.GetCreateParams (frm
);
109 Assert
.AreEqual (FormStartPosition
.CenterParent
, frm
.StartPosition
, "$A2");
110 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#A2");
112 frm
.StartPosition
= FormStartPosition
.CenterScreen
;
113 cp
= TestHelper
.GetCreateParams (frm
);
114 Assert
.AreEqual (FormStartPosition
.CenterScreen
, frm
.StartPosition
, "$A3");
115 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");
117 frm
.StartPosition
= FormStartPosition
.Manual
;
118 cp
= TestHelper
.GetCreateParams (frm
);
119 Assert
.AreEqual (FormStartPosition
.Manual
, frm
.StartPosition
, "$A4");
120 Assert
.AreEqual (new Point (23, 45).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#A4");
122 frm
.StartPosition
= FormStartPosition
.WindowsDefaultBounds
;
123 cp
= TestHelper
.GetCreateParams (frm
);
124 Assert
.AreEqual (FormStartPosition
.WindowsDefaultBounds
, frm
.StartPosition
, "$A5");
125 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#A5");
127 frm
.StartPosition
= FormStartPosition
.WindowsDefaultLocation
;
128 cp
= TestHelper
.GetCreateParams (frm
);
129 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, frm
.StartPosition
, "$A6");
130 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#A6");
137 public void MdiFormStartupPositionTest ()
140 using (Form Main
= new Form ()) {
141 Main
.IsMdiContainer
= true;
142 Main
.ShowInTaskbar
= false;
145 using (Form frm
= new Form ()) {
146 frm
.MdiParent
= Main
;
147 cp
= TestHelper
.GetCreateParams (frm
);
148 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, frm
.StartPosition
, "$01");
149 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#01");
151 frm
.StartPosition
= FormStartPosition
.CenterParent
;
152 cp
= TestHelper
.GetCreateParams (frm
);
153 Assert
.AreEqual (FormStartPosition
.CenterParent
, frm
.StartPosition
, "$01");
154 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#02");
156 frm
.StartPosition
= FormStartPosition
.CenterScreen
;
157 cp
= TestHelper
.GetCreateParams (frm
);
158 Assert
.AreEqual (FormStartPosition
.CenterScreen
, frm
.StartPosition
, "$01");
159 Assert
.AreEqual (new Point (0, 0).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#03");
161 frm
.StartPosition
= FormStartPosition
.Manual
;
162 cp
= TestHelper
.GetCreateParams (frm
);
163 Assert
.AreEqual (FormStartPosition
.Manual
, frm
.StartPosition
, "$01");
164 Assert
.AreEqual (new Point (0, 0).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#04");
166 frm
.StartPosition
= FormStartPosition
.WindowsDefaultBounds
;
167 cp
= TestHelper
.GetCreateParams (frm
);
168 Assert
.AreEqual (FormStartPosition
.WindowsDefaultBounds
, frm
.StartPosition
, "$01");
169 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#05");
171 frm
.StartPosition
= FormStartPosition
.WindowsDefaultLocation
;
172 cp
= TestHelper
.GetCreateParams (frm
);
173 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, frm
.StartPosition
, "$01");
174 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#06");
179 using (Form frm
= new Form ()) {
180 frm
.MdiParent
= Main
;
181 frm
.Location
= new Point (23, 45);
183 cp
= TestHelper
.GetCreateParams (frm
);
184 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, frm
.StartPosition
, "$A1");
185 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#A1");
187 frm
.StartPosition
= FormStartPosition
.CenterParent
;
188 cp
= TestHelper
.GetCreateParams (frm
);
189 Assert
.AreEqual (FormStartPosition
.CenterParent
, frm
.StartPosition
, "$A2");
190 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#A2");
192 frm
.StartPosition
= FormStartPosition
.CenterScreen
;
193 cp
= TestHelper
.GetCreateParams (frm
);
194 Assert
.AreEqual (FormStartPosition
.CenterScreen
, frm
.StartPosition
, "$A3");
195 Assert
.AreEqual (new Point (0, 0).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#A3");
197 frm
.StartPosition
= FormStartPosition
.Manual
;
198 cp
= TestHelper
.GetCreateParams (frm
);
199 Assert
.AreEqual (FormStartPosition
.Manual
, frm
.StartPosition
, "$A4");
200 Assert
.AreEqual (new Point (23, 45).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#A4");
202 frm
.StartPosition
= FormStartPosition
.WindowsDefaultBounds
;
203 cp
= TestHelper
.GetCreateParams (frm
);
204 Assert
.AreEqual (FormStartPosition
.WindowsDefaultBounds
, frm
.StartPosition
, "$A5");
205 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#A5");
207 frm
.StartPosition
= FormStartPosition
.WindowsDefaultLocation
;
208 cp
= TestHelper
.GetCreateParams (frm
);
209 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, frm
.StartPosition
, "$A6");
210 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#A6");
217 using (Form frm
= new Form ()) {
218 frm
.MdiParent
= Main
;
219 frm
.Location
= new Point (34, 56);
221 cp
= TestHelper
.GetCreateParams (frm
);
222 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, frm
.StartPosition
, "$B1");
223 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#B1");
225 frm
.StartPosition
= FormStartPosition
.CenterParent
;
226 cp
= TestHelper
.GetCreateParams (frm
);
227 Assert
.AreEqual (FormStartPosition
.CenterParent
, frm
.StartPosition
, "$B2");
228 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#B2");
230 frm
.StartPosition
= FormStartPosition
.CenterScreen
;
231 cp
= TestHelper
.GetCreateParams (frm
);
232 Assert
.AreEqual (FormStartPosition
.CenterScreen
, frm
.StartPosition
, "$B3");
233 Assert
.AreEqual (new Point (0, 0).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#B3");
235 frm
.StartPosition
= FormStartPosition
.Manual
;
236 cp
= TestHelper
.GetCreateParams (frm
);
237 Assert
.AreEqual (FormStartPosition
.Manual
, frm
.StartPosition
, "$B4");
238 Assert
.AreEqual (new Point (34, 56).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#B4");
240 frm
.StartPosition
= FormStartPosition
.WindowsDefaultBounds
;
241 cp
= TestHelper
.GetCreateParams (frm
);
242 Assert
.AreEqual (FormStartPosition
.WindowsDefaultBounds
, frm
.StartPosition
, "$B5");
243 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#B5");
245 frm
.StartPosition
= FormStartPosition
.WindowsDefaultLocation
;
246 cp
= TestHelper
.GetCreateParams (frm
);
247 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, frm
.StartPosition
, "$B6");
248 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#B6");
253 Main
.Size
= new Size (600, 600);
254 using (Form frm
= new Form ()) {
255 frm
.MdiParent
= Main
;
256 frm
.Location
= new Point (34, 56);
258 cp
= TestHelper
.GetCreateParams (frm
);
259 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, frm
.StartPosition
, "$C1");
260 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#C1");
262 frm
.StartPosition
= FormStartPosition
.CenterParent
;
263 cp
= TestHelper
.GetCreateParams (frm
);
264 Assert
.AreEqual (FormStartPosition
.CenterParent
, frm
.StartPosition
, "$C2");
265 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#C2");
267 frm
.StartPosition
= FormStartPosition
.CenterScreen
;
268 cp
= TestHelper
.GetCreateParams (frm
);
269 Assert
.AreEqual (FormStartPosition
.CenterScreen
, frm
.StartPosition
, "$C3");
270 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");
272 frm
.StartPosition
= FormStartPosition
.Manual
;
273 cp
= TestHelper
.GetCreateParams (frm
);
274 Assert
.AreEqual (FormStartPosition
.Manual
, frm
.StartPosition
, "$C4");
275 Assert
.AreEqual (new Point (34, 56).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#C4");
277 frm
.StartPosition
= FormStartPosition
.WindowsDefaultBounds
;
278 cp
= TestHelper
.GetCreateParams (frm
);
279 Assert
.AreEqual (FormStartPosition
.WindowsDefaultBounds
, frm
.StartPosition
, "$C5");
280 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#C5");
282 frm
.StartPosition
= FormStartPosition
.WindowsDefaultLocation
;
283 cp
= TestHelper
.GetCreateParams (frm
);
284 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, frm
.StartPosition
, "$C6");
285 Assert
.AreEqual (new Point (int.MinValue
, int.MinValue
).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#C6");
293 public void ParentedFormStartupPositionTest ()
296 using (Form Main
= new Form ()) {
297 Main
.ShowInTaskbar
= false;
300 using (Form frm
= new Form ()) {
301 frm
.TopLevel
= false;
302 Main
.Controls
.Add (frm
);
303 cp
= TestHelper
.GetCreateParams (frm
);
304 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, frm
.StartPosition
, "$01");
305 Assert
.AreEqual (new Point (0, 0).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#01");
307 frm
.StartPosition
= FormStartPosition
.CenterParent
;
308 cp
= TestHelper
.GetCreateParams (frm
);
309 Assert
.AreEqual (FormStartPosition
.CenterParent
, frm
.StartPosition
, "$02");
310 Assert
.AreEqual (new Point (0, 0).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#02");
312 frm
.StartPosition
= FormStartPosition
.CenterScreen
;
313 cp
= TestHelper
.GetCreateParams (frm
);
314 Assert
.AreEqual (FormStartPosition
.CenterScreen
, frm
.StartPosition
, "$03");
315 Assert
.AreEqual (new Point (0, 0).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#03");
317 frm
.StartPosition
= FormStartPosition
.Manual
;
318 cp
= TestHelper
.GetCreateParams (frm
);
319 Assert
.AreEqual (FormStartPosition
.Manual
, frm
.StartPosition
, "$04");
320 Assert
.AreEqual (new Point (0, 0).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#04");
322 frm
.StartPosition
= FormStartPosition
.WindowsDefaultBounds
;
323 cp
= TestHelper
.GetCreateParams (frm
);
324 Assert
.AreEqual (FormStartPosition
.WindowsDefaultBounds
, frm
.StartPosition
, "$05");
325 Assert
.AreEqual (new Point (0, 0).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#05");
327 frm
.StartPosition
= FormStartPosition
.WindowsDefaultLocation
;
328 cp
= TestHelper
.GetCreateParams (frm
);
329 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, frm
.StartPosition
, "$06");
330 Assert
.AreEqual (new Point (0, 0).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#06");
335 using (Form frm
= new Form ()) {
336 frm
.TopLevel
= false;
337 Main
.Controls
.Add (frm
);
338 frm
.Location
= new Point (23, 45);
340 cp
= TestHelper
.GetCreateParams (frm
);
341 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, frm
.StartPosition
, "$A1");
342 Assert
.AreEqual (new Point (23, 45).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#A1");
344 frm
.StartPosition
= FormStartPosition
.CenterParent
;
345 cp
= TestHelper
.GetCreateParams (frm
);
346 Assert
.AreEqual (FormStartPosition
.CenterParent
, frm
.StartPosition
, "$A2");
347 Assert
.AreEqual (new Point (23, 45).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#A2");
349 frm
.StartPosition
= FormStartPosition
.CenterScreen
;
350 cp
= TestHelper
.GetCreateParams (frm
);
351 Assert
.AreEqual (FormStartPosition
.CenterScreen
, frm
.StartPosition
, "$A3");
352 Assert
.AreEqual (new Point (23, 45).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#A3");
354 frm
.StartPosition
= FormStartPosition
.Manual
;
355 cp
= TestHelper
.GetCreateParams (frm
);
356 Assert
.AreEqual (FormStartPosition
.Manual
, frm
.StartPosition
, "$A4");
357 Assert
.AreEqual (new Point (23, 45).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#A4");
359 frm
.StartPosition
= FormStartPosition
.WindowsDefaultBounds
;
360 cp
= TestHelper
.GetCreateParams (frm
);
361 Assert
.AreEqual (FormStartPosition
.WindowsDefaultBounds
, frm
.StartPosition
, "$A5");
362 Assert
.AreEqual (new Point (23, 45).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#A5");
364 frm
.StartPosition
= FormStartPosition
.WindowsDefaultLocation
;
365 cp
= TestHelper
.GetCreateParams (frm
);
366 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, frm
.StartPosition
, "$A6");
367 Assert
.AreEqual (new Point (23, 45).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#A6");
374 using (Form frm
= new Form ()) {
375 frm
.TopLevel
= false;
376 Main
.Controls
.Add (frm
);
377 frm
.Location
= new Point (34, 56);
379 cp
= TestHelper
.GetCreateParams (frm
);
380 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, frm
.StartPosition
, "$B1");
381 Assert
.AreEqual (new Point (34, 56).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#B1");
383 frm
.StartPosition
= FormStartPosition
.CenterParent
;
384 cp
= TestHelper
.GetCreateParams (frm
);
385 Assert
.AreEqual (FormStartPosition
.CenterParent
, frm
.StartPosition
, "$B2");
386 Assert
.AreEqual (new Point (34, 56).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#B2");
388 frm
.StartPosition
= FormStartPosition
.CenterScreen
;
389 cp
= TestHelper
.GetCreateParams (frm
);
390 Assert
.AreEqual (FormStartPosition
.CenterScreen
, frm
.StartPosition
, "$B3");
391 Assert
.AreEqual (new Point (34, 56).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#B3");
393 frm
.StartPosition
= FormStartPosition
.Manual
;
394 cp
= TestHelper
.GetCreateParams (frm
);
395 Assert
.AreEqual (FormStartPosition
.Manual
, frm
.StartPosition
, "$B4");
396 Assert
.AreEqual (new Point (34, 56).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#B4");
398 frm
.StartPosition
= FormStartPosition
.WindowsDefaultBounds
;
399 cp
= TestHelper
.GetCreateParams (frm
);
400 Assert
.AreEqual (FormStartPosition
.WindowsDefaultBounds
, frm
.StartPosition
, "$B5");
401 Assert
.AreEqual (new Point (34, 56).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#B5");
403 frm
.StartPosition
= FormStartPosition
.WindowsDefaultLocation
;
404 cp
= TestHelper
.GetCreateParams (frm
);
405 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, frm
.StartPosition
, "$B6");
406 Assert
.AreEqual (new Point (34, 56).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#B6");
412 Main
.Size
= new Size (600, 600);
413 using (Form frm
= new Form ()) {
414 frm
.TopLevel
= false;
415 Main
.Controls
.Add (frm
);
416 frm
.Location
= new Point (34, 56);
418 cp
= TestHelper
.GetCreateParams (frm
);
419 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, frm
.StartPosition
, "$C1");
420 Assert
.AreEqual (new Point (34, 56).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#C1");
422 frm
.StartPosition
= FormStartPosition
.CenterParent
;
423 cp
= TestHelper
.GetCreateParams (frm
);
424 Assert
.AreEqual (FormStartPosition
.CenterParent
, frm
.StartPosition
, "$C2");
425 Assert
.AreEqual (new Point (34, 56).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#C2");
427 frm
.StartPosition
= FormStartPosition
.CenterScreen
;
428 cp
= TestHelper
.GetCreateParams (frm
);
429 Assert
.AreEqual (FormStartPosition
.CenterScreen
, frm
.StartPosition
, "$C3");
430 Assert
.AreEqual (new Point (34, 56).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#C3");
432 frm
.StartPosition
= FormStartPosition
.Manual
;
433 cp
= TestHelper
.GetCreateParams (frm
);
434 Assert
.AreEqual (FormStartPosition
.Manual
, frm
.StartPosition
, "$C4");
435 Assert
.AreEqual (new Point (34, 56).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#C4");
437 frm
.StartPosition
= FormStartPosition
.WindowsDefaultBounds
;
438 cp
= TestHelper
.GetCreateParams (frm
);
439 Assert
.AreEqual (FormStartPosition
.WindowsDefaultBounds
, frm
.StartPosition
, "$C5");
440 Assert
.AreEqual (new Point (34, 56).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#C5");
442 frm
.StartPosition
= FormStartPosition
.WindowsDefaultLocation
;
443 cp
= TestHelper
.GetCreateParams (frm
);
444 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, frm
.StartPosition
, "$C6");
445 Assert
.AreEqual (new Point (34, 56).ToString (), new Point (cp
.X
, cp
.Y
).ToString (), "#C6");
453 public void ClientSizeTest ()
455 Form form
= new Form ();
456 Assert
.IsFalse (form
.ClientSize
== form
.Size
);
460 [Category ("NotWorking")]
461 public void FormBorderStyleTest ()
463 Form form
= new Form ();
464 Rectangle boundsBeforeBorderStyleChange
= form
.Bounds
;
465 Rectangle clientRectangleBeforeBorderStyleChange
= form
.ClientRectangle
;
466 form
.FormBorderStyle
= FormBorderStyle
.None
;
467 Assert
.AreEqual (form
.Bounds
, boundsBeforeBorderStyleChange
, "#A1");
468 Assert
.AreEqual (form
.ClientRectangle
, clientRectangleBeforeBorderStyleChange
, "#A2");
471 form
.FormBorderStyle
= FormBorderStyle
.Sizable
;
472 boundsBeforeBorderStyleChange
= form
.Bounds
;
473 clientRectangleBeforeBorderStyleChange
= form
.ClientRectangle
;
474 form
.FormBorderStyle
= FormBorderStyle
.None
;
475 Assert
.IsFalse (form
.Bounds
== boundsBeforeBorderStyleChange
, "#B1");
476 Assert
.AreEqual (form
.ClientRectangle
, clientRectangleBeforeBorderStyleChange
, "#B2");
478 form
.Visible
= false;
479 form
.FormBorderStyle
= FormBorderStyle
.Sizable
;
480 boundsBeforeBorderStyleChange
= form
.Bounds
;
481 clientRectangleBeforeBorderStyleChange
= form
.ClientRectangle
;
482 form
.FormBorderStyle
= FormBorderStyle
.None
;
483 Assert
.IsFalse (form
.Bounds
== boundsBeforeBorderStyleChange
, "#C1");
484 Assert
.AreEqual (form
.ClientRectangle
, clientRectangleBeforeBorderStyleChange
, "#C2");
488 [Category ("NotWorking")]
489 public void MaximizedParentedFormTest ()
491 using (Form Main
= new Form ()) {
492 Form Child
= new Form ();
493 Child
.TopLevel
= false;
494 Main
.Controls
.Add (Child
);
495 Main
.ShowInTaskbar
= false;
498 Child
.WindowState
= FormWindowState
.Maximized
;
499 Child
.Visible
= true;
500 // The exact negative value depends on the border with, but it should always be < 0.
501 Assert
.IsTrue (Child
.Location
.X
< 0 && Child
.Location
.Y
< 0, "#A1");
505 [Category ("NotWorking")]
506 public void ParentedFormEventTest ()
509 using (Form Main
= new Form ()) {
510 Form Child
= new Form ();
511 Child
.TopLevel
= false;
512 Child
.Visible
= true;
513 Main
.ShowInTaskbar
= false;
516 EventLogger log
= new EventLogger (Child
);
517 Assert
.AreEqual (true, Child
.Visible
, "#A0");
518 Main
.Controls
.Add (Child
);
519 Assert
.AreEqual (true, Child
.Visible
, "#B0");
520 Assert
.AreEqual ("ParentChanged;BindingContextChanged;Layout;VisibleChanged;BindingContextChanged;BindingContextChanged", log
.EventsJoined (), "#B1");
524 [NUnit
.Framework
.Category ("NotWorking")]
525 public void FormCreateParamsStyleTest ()
529 using (frm
= new Form ()) {
530 Assert
.AreEqual (WindowStyles
.WS_TILED
| WindowStyles
.WS_TILEDWINDOW
| WindowStyles
.WS_CLIPCHILDREN
, ((WindowStyles
) TestHelper
.GetCreateParams (frm
).Style
), "#01-Style");
531 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");
534 using (frm
= new Form ()) {
535 frm
.AllowDrop
= !frm
.AllowDrop
;
536 Assert
.AreEqual (WindowStyles
.WS_TILED
| WindowStyles
.WS_TILEDWINDOW
| WindowStyles
.WS_CLIPCHILDREN
, ((WindowStyles
)TestHelper
.GetCreateParams (frm
).Style
), "#02-Style");
537 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");
540 using (frm
= new Form ()) {
541 frm
.AllowTransparency
= !frm
.AllowTransparency
;
542 Assert
.AreEqual (WindowStyles
.WS_TILED
| WindowStyles
.WS_TILEDWINDOW
| WindowStyles
.WS_CLIPCHILDREN
, ((WindowStyles
)TestHelper
.GetCreateParams (frm
).Style
), "#03-Style");
543 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");
546 using (frm
= new Form ()) {
548 Assert
.AreEqual (WindowStyles
.WS_TILED
| WindowStyles
.WS_TILEDWINDOW
| WindowStyles
.WS_CLIPCHILDREN
, ((WindowStyles
)TestHelper
.GetCreateParams (frm
).Style
), "#04-Style");
549 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");
552 using (frm
= new Form ()) {
553 frm
.TransparencyKey
= Color
.Cyan
;
554 Assert
.AreEqual (WindowStyles
.WS_TILED
| WindowStyles
.WS_TILEDWINDOW
| WindowStyles
.WS_CLIPCHILDREN
, ((WindowStyles
)TestHelper
.GetCreateParams (frm
).Style
), "#05-Style");
555 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");
558 using (frm
= new Form ()) {
559 frm
.CausesValidation
= !frm
.CausesValidation
;
560 Assert
.AreEqual (WindowStyles
.WS_TILED
| WindowStyles
.WS_TILEDWINDOW
| WindowStyles
.WS_CLIPCHILDREN
, ((WindowStyles
)TestHelper
.GetCreateParams (frm
).Style
), "#06-Style");
561 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");
564 using (frm
= new Form ()) {
565 frm
.ControlBox
= !frm
.ControlBox
;
566 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");
567 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");
570 using (frm
= new Form ()) {
572 Assert
.AreEqual (WindowStyles
.WS_TILED
| WindowStyles
.WS_TILEDWINDOW
| WindowStyles
.WS_CLIPCHILDREN
, ((WindowStyles
)TestHelper
.GetCreateParams (frm
).Style
), "#08-Style");
573 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");
576 using (frm
= new Form ()) {
577 frm
.FormBorderStyle
= FormBorderStyle
.Fixed3D
;
578 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");
579 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");
582 using (frm
= new Form ()) {
583 frm
.FormBorderStyle
= FormBorderStyle
.FixedDialog
;
584 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");
585 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");
588 using (frm
= new Form ()) {
589 frm
.FormBorderStyle
= FormBorderStyle
.FixedSingle
;
590 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");
591 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");
594 using (frm
= new Form ()) {
595 frm
.FormBorderStyle
= FormBorderStyle
.FixedToolWindow
;
596 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");
597 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");
600 using (frm
= new Form ()) {
601 frm
.FormBorderStyle
= FormBorderStyle
.None
;
602 Assert
.AreEqual (WindowStyles
.WS_TILED
| WindowStyles
.WS_TABSTOP
| WindowStyles
.WS_CLIPCHILDREN
, ((WindowStyles
)TestHelper
.GetCreateParams (frm
).Style
), "#14-Style");
603 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");
606 using (frm
= new Form ()) {
607 frm
.FormBorderStyle
= FormBorderStyle
.Sizable
;
608 Assert
.AreEqual (WindowStyles
.WS_TILED
| WindowStyles
.WS_TILEDWINDOW
| WindowStyles
.WS_CLIPCHILDREN
, ((WindowStyles
)TestHelper
.GetCreateParams (frm
).Style
), "#15-Style");
609 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");
612 using (frm
= new Form ()) {
613 frm
.FormBorderStyle
= FormBorderStyle
.SizableToolWindow
;
614 Assert
.AreEqual (WindowStyles
.WS_TILED
| WindowStyles
.WS_TILEDWINDOW
| WindowStyles
.WS_CLIPCHILDREN
, ((WindowStyles
)TestHelper
.GetCreateParams (frm
).Style
), "#16-Style");
615 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");
618 using (frm
= new Form ()) {
619 frm
.HelpButton
= !frm
.HelpButton
;
620 Assert
.AreEqual (WindowStyles
.WS_TILED
| WindowStyles
.WS_TILEDWINDOW
| WindowStyles
.WS_CLIPCHILDREN
, ((WindowStyles
)TestHelper
.GetCreateParams (frm
).Style
), "#17-Style");
621 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");
624 using (frm
= new Form ()) {
626 Assert
.AreEqual (WindowStyles
.WS_TILED
| WindowStyles
.WS_TILEDWINDOW
| WindowStyles
.WS_CLIPCHILDREN
, ((WindowStyles
)TestHelper
.GetCreateParams (frm
).Style
), "#18-Style");
627 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");
630 using (frm
= new Form ()) {
631 frm
.Icon
= SystemIcons
.Asterisk
;
632 Assert
.AreEqual (WindowStyles
.WS_TILED
| WindowStyles
.WS_TILEDWINDOW
| WindowStyles
.WS_CLIPCHILDREN
, ((WindowStyles
)TestHelper
.GetCreateParams (frm
).Style
), "#19-Style");
633 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");
636 using (frm
= new Form ()) {
637 frm
.IsMdiContainer
= !frm
.IsMdiContainer
;
638 Assert
.AreEqual (WindowStyles
.WS_TILED
| WindowStyles
.WS_TILEDWINDOW
| WindowStyles
.WS_CLIPCHILDREN
, ((WindowStyles
)TestHelper
.GetCreateParams (frm
).Style
), "#20-Style");
639 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");
642 using (frm
= new Form ()) {
643 frm
.MaximizeBox
= !frm
.MaximizeBox
;
644 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");
645 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");
648 using (frm
= new Form ()) {
649 frm
.MinimizeBox
= !frm
.MinimizeBox
;
650 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");
651 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");
654 using (frm
= new Form ()) {
655 frm
.ShowIcon
= !frm
.ShowIcon
;
656 Assert
.AreEqual (WindowStyles
.WS_TILED
| WindowStyles
.WS_TILEDWINDOW
| WindowStyles
.WS_CLIPCHILDREN
, ((WindowStyles
)TestHelper
.GetCreateParams (frm
).Style
), "#23-Style");
657 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");
660 using (frm
= new Form ()) {
661 frm
.ShowInTaskbar
= !frm
.ShowInTaskbar
;
662 Assert
.AreEqual (WindowStyles
.WS_TILED
| WindowStyles
.WS_TILEDWINDOW
| WindowStyles
.WS_CLIPCHILDREN
, ((WindowStyles
)TestHelper
.GetCreateParams (frm
).Style
), "#24-Style");
663 Assert
.AreEqual (WindowExStyles
.WS_EX_LEFT
| WindowExStyles
.WS_EX_RIGHTSCROLLBAR
| WindowExStyles
.WS_EX_CONTROLPARENT
, ((WindowExStyles
)TestHelper
.GetCreateParams (frm
).ExStyle
), "#24-ExStyle");
667 using (frm
= new Form ()) {
668 frm
.TabStop
= !frm
.TabStop
;
669 Assert
.AreEqual (WindowStyles
.WS_TILED
| WindowStyles
.WS_TILEDWINDOW
| WindowStyles
.WS_CLIPCHILDREN
, ((WindowStyles
)TestHelper
.GetCreateParams (frm
).Style
), "#25-Style");
670 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");
673 using (frm
= new Form ()) {
674 frm
.TopLevel
= !frm
.TopLevel
;
675 Assert
.AreEqual (WindowStyles
.WS_TILED
| WindowStyles
.WS_TILEDWINDOW
| WindowStyles
.WS_CLIPCHILDREN
| WindowStyles
.WS_CLIPSIBLINGS
| WindowStyles
.WS_CHILD
, ((WindowStyles
)TestHelper
.GetCreateParams (frm
).Style
), "#26-Style");
676 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");
679 using (frm
= new Form ()) {
680 frm
.Visible
= !frm
.Visible
;
681 Assert
.AreEqual (WindowStyles
.WS_TILED
| WindowStyles
.WS_TILEDWINDOW
| WindowStyles
.WS_CLIPCHILDREN
, ((WindowStyles
)TestHelper
.GetCreateParams (frm
).Style
), "#27-Style");
682 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");
685 using (frm
= new Form ()) {
686 frm
.ControlBox
= false;
688 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");
689 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");
694 public void FormParentedTest ()
696 using (Form frm
= new Form ()) {
697 Form frm2
= new Form ();
698 frm2
.TopLevel
= false;
699 frm
.ShowInTaskbar
= false;
700 frm2
.ShowInTaskbar
= false;
704 EventLogger log
= new EventLogger (frm
);
705 EventLogger log2
= new EventLogger (frm2
);
707 frm
.Controls
.Add (frm2
);
709 Assert
.IsTrue (log2
.EventRaised ("ParentChanged"), "#C1");
710 Assert
.IsTrue (log
.EventRaised ("ControlAdded"), "#P1");
711 Assert
.AreSame (frm
, frm2
.Parent
, "#02");
716 public void FormPropertyTest ()
718 Form myform
= new Form ();
719 myform
.Visible
= true;
720 myform
.Text
= "NewForm";
721 myform
.Name
= "FormTest";
722 Assert
.IsNull (myform
.AcceptButton
, "#1");
723 Assert
.IsNull (myform
.ActiveMdiChild
, "#2");
724 Assert
.IsFalse (myform
.AutoScale
, "#3");
725 Assert
.IsNull (myform
.CancelButton
, "#6");
726 Assert
.IsTrue (myform
.ControlBox
, "#9");
727 Assert
.IsTrue (myform
.DesktopBounds
.X
> 0, "#10a");
728 Assert
.IsTrue (myform
.DesktopBounds
.Y
> 0, "#10b");
729 Assert
.AreEqual (300, myform
.DesktopBounds
.Height
, "#10c");
730 Assert
.AreEqual (300, myform
.DesktopBounds
.Width
, "#10d");
731 Assert
.IsTrue (myform
.DesktopLocation
.X
> 0, "#11a");
732 Assert
.IsTrue (myform
.DesktopLocation
.Y
> 0, "#11b");
733 Assert
.AreEqual (DialogResult
.None
, myform
.DialogResult
, "#12");
734 Assert
.AreEqual (FormBorderStyle
.Sizable
, myform
.FormBorderStyle
, "#13");
735 Assert
.IsFalse (myform
.HelpButton
, "#14");
736 Assert
.AreEqual ("System.Drawing.Icon", myform
.Icon
.GetType ().ToString (), "#15");
737 Assert
.IsFalse (myform
.IsMdiChild
, "#16");
738 Assert
.IsFalse (myform
.IsMdiContainer
, "#17");
739 Assert
.IsFalse (myform
.KeyPreview
, "#18");
740 Assert
.IsTrue (myform
.MaximizeBox
, "#19");
741 Assert
.AreEqual (0, myform
.MaximumSize
.Height
, "#20a");
742 Assert
.AreEqual (0, myform
.MaximumSize
.Width
, "#20b");
743 Assert
.AreEqual (0, myform
.MdiChildren
.Length
, "#21a");
744 Assert
.AreEqual (1, myform
.MdiChildren
.Rank
, "#21b");
745 Assert
.IsFalse (myform
.MdiChildren
.IsSynchronized
, "#21c");
746 Assert
.IsNull (myform
.MdiParent
, "#22");
747 Assert
.IsNull (myform
.Menu
, "#23");
748 Assert
.IsNull (myform
.MergedMenu
, "#24");
749 Assert
.IsTrue (myform
.MinimizeBox
, "#25");
750 Assert
.AreEqual (0, myform
.MinimumSize
.Height
, "#26a");
751 Assert
.AreEqual (0, myform
.MinimumSize
.Width
, "#26b");
752 Assert
.IsTrue (myform
.MinimumSize
.IsEmpty
, "#26c");
753 Assert
.IsFalse (myform
.Modal
, "#27");
754 Assert
.AreEqual (1, myform
.Opacity
, "#28");
755 Assert
.AreEqual (0, myform
.OwnedForms
.Length
, "#29a");
756 Assert
.AreEqual (1, myform
.OwnedForms
.Rank
, "#29b");
757 Assert
.IsNull (myform
.Owner
, "#30");
758 Assert
.IsTrue (myform
.ShowInTaskbar
, "#31");
759 Assert
.AreEqual (300, myform
.Size
.Height
, "#32a");
760 Assert
.AreEqual (300, myform
.Size
.Width
, "#32b");
761 Assert
.AreEqual (SizeGripStyle
.Auto
, myform
.SizeGripStyle
, "#33");
762 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, myform
.StartPosition
, "#34");
763 Assert
.IsTrue (myform
.TopLevel
, "#35");
764 Assert
.IsFalse (myform
.TopMost
, "#36");
765 Assert
.AreEqual (Color
.Empty
, myform
.TransparencyKey
, "#37");
766 Assert
.AreEqual (FormWindowState
.Normal
, myform
.WindowState
, "#38");
767 Assert
.AreEqual (ImeMode
.NoControl
, myform
.ImeMode
, "#39");
772 [Category ("NotWorking")]
773 public void ActivateTest ()
775 Form myform
= new Form ();
776 myform
.ShowInTaskbar
= false;
777 myform
.Visible
= true;
778 myform
.Text
= "NewForm";
779 myform
.Name
= "FormTest";
781 Assert
.AreEqual (true, myform
.Focus (), "#40");
786 public void AddOwnedFormTest ()
788 Form parent
= new Form ();
789 parent
.ShowInTaskbar
= false;
790 parent
.Text
= "NewParent";
791 Form ownedForm
= new Form ();
792 ownedForm
.ShowInTaskbar
= false;
793 ownedForm
.Text
= "Owned Form";
794 parent
.AddOwnedForm (ownedForm
);
796 Assert
.AreEqual ("NewParent", ownedForm
.Owner
.Text
, "#41");
797 ownedForm
.Dispose ();
802 public void IsHandleCreated ()
804 Form main
= new Form ();
806 main
.IsMdiContainer
= true;
807 main
.ShowInTaskbar
= false;
808 Assert
.IsFalse (main
.IsHandleCreated
, "#1");
810 Form child
= new Form ();
811 child
.MdiParent
= main
;
812 child
.WindowState
= FormWindowState
.Maximized
;
813 Assert
.IsFalse (main
.IsHandleCreated
, "#2");
816 Assert
.IsFalse (child
.IsHandleCreated
, "#3");
817 Assert
.IsFalse (main
.IsHandleCreated
, "#4");
820 Assert
.IsTrue (child
.IsHandleCreated
, "#5");
821 Assert
.IsTrue (main
.IsHandleCreated
, "#6");
828 public void RemoveOwnedFormTest ()
830 Form myform
= new Form ();
831 myform
.ShowInTaskbar
= false;
832 myform
.Text
= "NewForm";
833 myform
.Name
= "FormTest";
834 myform
.RemoveOwnedForm (myform
);
836 Assert
.AreEqual (null, myform
.Owner
, "#44");
841 public void SetDesktopBoundsTest ()
843 Form myform
= new Form ();
844 myform
.ShowInTaskbar
= false;
845 myform
.Visible
= true;
846 myform
.Text
= "NewForm";
847 myform
.Name
= "FormTest";
848 myform
.SetDesktopBounds (10, 10, 200 , 200);
849 Assert
.AreEqual (200, myform
.DesktopBounds
.Height
, "#45");
854 public void SetDesktopLocationTest ()
856 Form myform
= new Form ();
857 myform
.ShowInTaskbar
= false;
858 myform
.Visible
= true;
859 myform
.Text
= "NewForm";
860 myform
.Name
= "FormTest";
861 myform
.SetDesktopLocation (10, 10);
862 Assert
.AreEqual (10, myform
.DesktopLocation
.X
, "#46");
867 public void SetDialogResultOutOfRange ()
869 Form myform
= new Form ();
870 myform
.ShowInTaskbar
= false;
872 myform
.DialogResult
= (DialogResult
) (-1);
874 } catch (InvalidEnumArgumentException
) {
878 myform
.DialogResult
= (DialogResult
) ((int) DialogResult
.No
+ 1);
880 } catch (InvalidEnumArgumentException
) {
885 void myform_set_dialogresult (object sender
, EventArgs e
)
887 Form f
= (Form
)sender
;
889 f
.DialogResult
= DialogResult
.OK
;
892 void myform_close (object sender
, EventArgs e
)
894 Form f
= (Form
)sender
;
900 public void SetDialogResult ()
902 Form myform
= new Form ();
903 myform
.ShowInTaskbar
= false;
904 myform
.Visible
= true;
906 myform
.DialogResult
= DialogResult
.Cancel
;
908 Assert
.IsTrue (myform
.Visible
, "A1");
909 Assert
.IsFalse (myform
.IsDisposed
, "A2");
913 Assert
.IsFalse (myform
.Visible
, "A3");
914 Assert
.IsTrue (myform
.IsDisposed
, "A4");
918 myform
= new Form ();
919 myform
.ShowInTaskbar
= false;
920 myform
.VisibleChanged
+= new EventHandler (myform_set_dialogresult
);
921 result
= myform
.ShowDialog ();
923 Assert
.AreEqual (result
, DialogResult
.OK
, "A5");
924 Assert
.IsFalse (myform
.Visible
, "A6");
925 Assert
.IsFalse (myform
.IsDisposed
, "A7");
927 myform
= new Form ();
928 myform
.ShowInTaskbar
= false;
929 myform
.VisibleChanged
+= new EventHandler (myform_close
);
930 result
= myform
.ShowDialog ();
932 Assert
.AreEqual (result
, DialogResult
.Cancel
, "A8");
933 Assert
.IsFalse (myform
.Visible
, "A9");
934 Assert
.IsFalse (myform
.IsDisposed
, "A10");
938 public void ShowDialog_Child ()
940 Form main
= new Form ();
941 main
.IsMdiContainer
= true;
942 Form child
= new Form ();
943 child
.MdiParent
= main
;
947 } catch (InvalidOperationException ex
) {
948 // Forms that are not top level forms cannot be displayed as a
949 // modal dialog. Remove the form from any parent form before
950 // calling ShowDialog.
951 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#2");
952 Assert
.IsNull (ex
.InnerException
, "#3");
953 Assert
.IsNotNull (ex
.Message
, "#4");
955 Assert
.IsNull (child
.Owner
, "#5");
961 public void ShowDialog_Disabled ()
963 Form form
= new Form ();
964 form
.Enabled
= false;
968 } catch (InvalidOperationException ex
) {
969 // Forms that are not enabled cannot be displayed as a modal
970 // dialog. Set the form's enabled property to true before
971 // calling ShowDialog.
972 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#A2");
973 Assert
.IsNull (ex
.InnerException
, "#A3");
974 Assert
.IsNotNull (ex
.Message
, "#A4");
976 Assert
.IsNull (form
.Owner
, "#A5");
979 Form main
= new Form ();
982 form
.Enabled
= false;
986 } catch (InvalidOperationException
) {
988 Assert
.IsNotNull (form
.Owner
, "#B2");
989 Assert
.AreSame (main
, form
.Owner
, "#B3");
995 [Category ("NotWorking")]
996 public void ShowDialog_Owner_Circular ()
998 Form main
= new Form ();
999 Form child
= new Form ();
1002 main
.ShowDialog (child
);
1004 } catch (ArgumentException ex
) {
1005 // A circular control reference has been made. A control cannot
1006 // be owned or parented to itself
1007 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#2");
1008 Assert
.IsNull (ex
.InnerException
, "#3");
1009 Assert
.IsNotNull (ex
.Message
, "#4");
1010 Assert
.IsNull (ex
.ParamName
, "#5");
1012 Assert
.IsNull (main
.Owner
, "#6");
1017 [Test
] // bug #80773
1018 public void ShowDialog_Owner_Self ()
1020 Form form
= new Form ();
1022 form
.ShowDialog (form
);
1023 Assert
.Fail ("#A1");
1024 } catch (ArgumentException ex
) {
1025 // Forms cannot own themselves or their owners
1026 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#A2");
1027 Assert
.IsNull (ex
.InnerException
, "#A3");
1028 Assert
.IsNotNull (ex
.Message
, "#A4");
1029 Assert
.IsNotNull (ex
.ParamName
, "#A5");
1030 Assert
.AreEqual ("owner", ex
.ParamName
, "#A6");
1032 Assert
.IsNull (form
.Owner
, "#A7");
1035 Form main
= new Form ();
1039 form
.ShowDialog (form
);
1040 Assert
.Fail ("#B1");
1041 } catch (ArgumentException
) {
1043 Assert
.IsNotNull (form
.Owner
);
1044 Assert
.AreSame (main
, form
.Owner
, "#B2");
1050 public void ShowDialog_Visible ()
1052 Form form
= new Form ();
1053 form
.ShowInTaskbar
= false;
1054 form
.Visible
= true;
1057 Assert
.Fail ("#A1");
1058 } catch (InvalidOperationException ex
) {
1059 // Forms that are already visible cannot be displayed as a modal
1060 // dialog. Set the form's visible property to false before
1061 // calling ShowDialog.
1062 Assert
.AreEqual (typeof (InvalidOperationException
), ex
.GetType (), "#A2");
1063 Assert
.IsNull (ex
.InnerException
, "#A3");
1064 Assert
.IsNotNull (ex
.Message
, "#A4");
1066 Assert
.IsNull (form
.Owner
, "#A5");
1069 Form main
= new Form ();
1072 form
.Visible
= true;
1075 Assert
.Fail ("#B1");
1076 } catch (InvalidOperationException
) {
1078 Assert
.IsNotNull (form
.Owner
, "#B2");
1079 Assert
.AreSame (main
, form
.Owner
, "#B3");
1084 [Test
] // bug #80604
1085 public void VisibleOnLoad ()
1087 MockForm form
= new MockForm ();
1088 form
.CloseOnLoad
= true;
1089 Application
.Run (form
);
1090 Assert
.IsTrue (form
.VisibleOnLoad
, "#1");
1093 form
= new MockForm ();
1094 form
.ShowInTaskbar
= false;
1096 Assert
.IsTrue (form
.VisibleOnLoad
, "#2");
1100 [Test
] // bug #80052
1101 [Category ("NotWorking")]
1102 public void Location ()
1108 Form formA
= new Form ();
1109 formA
.ShowInTaskbar
= false;
1110 formA
.StartPosition
= FormStartPosition
.CenterParent
;
1111 formA
.Location
= new Point (151, 251);
1114 Assert
.AreEqual (FormStartPosition
.CenterParent
, formA
.StartPosition
, "#A1");
1115 Assert
.IsFalse (formA
.Location
.X
== 151, "#A2");
1116 Assert
.IsFalse (formA
.Location
.Y
== 251, "#A3");
1118 formA
.Location
= new Point (311, 221);
1120 Assert
.AreEqual (FormStartPosition
.CenterParent
, formA
.StartPosition
, "#A4");
1121 Assert
.AreEqual (311, formA
.Location
.X
, "#A5");
1122 Assert
.AreEqual (221, formA
.Location
.Y
, "#A6");
1130 Form formB
= new Form ();
1131 formB
.ShowInTaskbar
= false;
1132 formB
.StartPosition
= FormStartPosition
.CenterScreen
;
1133 formB
.Location
= new Point (151, 251);
1136 Assert
.AreEqual (FormStartPosition
.CenterScreen
, formB
.StartPosition
, "#B1");
1137 Assert
.IsFalse (formB
.Location
.X
== 151, "#B2");
1138 Assert
.IsFalse (formB
.Location
.Y
== 251, "#B3");
1140 formB
.Location
= new Point (311, 221);
1142 Assert
.AreEqual (FormStartPosition
.CenterScreen
, formB
.StartPosition
, "#B4");
1143 Assert
.AreEqual (311, formB
.Location
.X
, "#B5");
1144 Assert
.AreEqual (221, formB
.Location
.Y
, "#B6");
1152 Form formC
= new Form ();
1153 formC
.ShowInTaskbar
= false;
1154 formC
.StartPosition
= FormStartPosition
.Manual
;
1155 formC
.Location
= new Point (151, 251);
1158 Assert
.AreEqual (FormStartPosition
.Manual
, formC
.StartPosition
, "#C1");
1159 Assert
.AreEqual (151, formC
.Location
.X
, "#C2");
1160 Assert
.AreEqual (251, formC
.Location
.Y
, "#C3");
1162 formC
.Location
= new Point (311, 221);
1164 Assert
.AreEqual (FormStartPosition
.Manual
, formC
.StartPosition
, "#C4");
1165 Assert
.AreEqual (311, formC
.Location
.X
, "#C5");
1166 Assert
.AreEqual (221, formC
.Location
.Y
, "#C6");
1171 // WindowsDefaultBounds
1174 Form formD
= new Form ();
1175 formD
.ShowInTaskbar
= false;
1176 formD
.StartPosition
= FormStartPosition
.WindowsDefaultBounds
;
1177 formD
.Location
= new Point (151, 251);
1180 Assert
.AreEqual (FormStartPosition
.WindowsDefaultBounds
, formD
.StartPosition
, "#D1");
1181 Assert
.IsFalse (formD
.Location
.X
== 151, "#D2");
1182 Assert
.IsFalse (formD
.Location
.Y
== 251, "#D3");
1184 formD
.Location
= new Point (311, 221);
1186 Assert
.AreEqual (FormStartPosition
.WindowsDefaultBounds
, formD
.StartPosition
, "#D4");
1187 Assert
.AreEqual (311, formD
.Location
.X
, "#D5");
1188 Assert
.AreEqual (221, formD
.Location
.Y
, "#D6");
1193 // WindowsDefaultLocation
1196 Form formE
= new Form ();
1197 formE
.ShowInTaskbar
= false;
1198 formE
.Location
= new Point (151, 251);
1201 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, formE
.StartPosition
, "#E1");
1202 Assert
.IsFalse (formE
.Location
.X
== 151, "#E2");
1203 Assert
.IsFalse (formE
.Location
.Y
== 251, "#E3");
1205 formE
.Location
= new Point (311, 221);
1207 Assert
.AreEqual (FormStartPosition
.WindowsDefaultLocation
, formE
.StartPosition
, "#E4");
1208 Assert
.AreEqual (311, formE
.Location
.X
, "#E5");
1209 Assert
.AreEqual (221, formE
.Location
.Y
, "#E6");
1215 public void DisposeOwnerTest ()
1217 Form f1
= new Form ();
1218 Form f2
= new Form ();
1224 Assert
.IsNull (f2
.Owner
, "1");
1225 Assert
.AreEqual (0, f1
.OwnedForms
.Length
, "2");
1229 [ExpectedException (typeof (ObjectDisposedException
))]
1230 public void AccessDisposedForm ()
1232 Form myform
= new Form ();
1233 myform
.ShowInTaskbar
= false;
1236 myform
.Close (); // this should result in the form being disposed
1237 myform
.Show (); // and this line should result in the ODE being thrown
1242 public void DoDestroyHandle ()
1246 public void DoRecreateHandle ()
1252 int handle_destroyed_count
;
1253 void handle_destroyed (object sender
, EventArgs e
)
1255 handle_destroyed_count
++;
1259 public void DestroyHandleTest ()
1261 handle_destroyed_count
= 0;
1263 MyForm f1
= new MyForm ();
1264 f1
.HandleDestroyed
+= new EventHandler (handle_destroyed
);
1266 f1
.DoDestroyHandle ();
1267 Assert
.AreEqual (1, handle_destroyed_count
, "1");
1270 f1
.HandleDestroyed
+= new EventHandler (handle_destroyed
);
1272 f1
.DoRecreateHandle ();
1273 Assert
.AreEqual (2, handle_destroyed_count
, "2");
1277 public void FormClose ()
1279 Form myform
= new Form ();
1280 myform
.ShowInTaskbar
= false;
1282 Assert
.IsFalse (myform
.Visible
, "A1");
1283 Assert
.IsFalse (myform
.IsDisposed
, "A2");
1287 Assert
.IsFalse (myform
.Visible
, "A3");
1288 Assert
.IsFalse (myform
.IsDisposed
, "A4");
1292 Assert
.IsTrue (myform
.Visible
, "A5");
1293 Assert
.IsFalse (myform
.IsDisposed
, "A6");
1297 Assert
.IsFalse (myform
.Visible
, "A7");
1298 Assert
.IsTrue (myform
.IsDisposed
, "A8");
1302 public void FormClose2 ()
1304 WMCloseWatcher f
= new WMCloseWatcher ();
1305 f
.ShowInTaskbar
= false;
1308 Assert
.IsFalse (f
.Visible
, "A1");
1310 Assert
.AreEqual (0, f
.close_count
, "A2");
1315 Assert
.AreEqual (1, f
.close_count
, "A3");
1318 class WMCloseWatcher
: Form
{
1319 public int close_count
;
1321 protected override void WndProc (ref Message msg
) {
1322 if (msg
.Msg
== 0x0010 /* WM_CLOSE */) {
1326 base.WndProc (ref msg
);
1330 class SwallowOnActivated
: Form
{
1331 protected override void OnActivated (EventArgs e
)
1336 protected override void OnCreateControl () {
1337 base.OnCreateControl ();
1341 class EnterTest
: Button
{
1342 protected override void OnEnter (EventArgs e
)
1348 public bool on_enter
;
1352 public void OnActivateEventHandlingTest1 ()
1354 if (TestHelper
.RunningOnUnix
) {
1355 Assert
.Ignore ("Relies on form.Show() synchronously generating WM_ACTIVATE");
1358 SwallowOnActivated f
= new SwallowOnActivated ();
1360 f
.ShowInTaskbar
= false;
1362 EnterTest c
= new EnterTest ();
1367 Assert
.IsTrue (c
.on_enter
, "1");
1374 public void FormClosingEvents ()
1377 Form f
= new Form ();
1378 string events
= string.Empty
;
1380 f
.Closing
+= new CancelEventHandler (delegate (Object obj
, CancelEventArgs e
) { events += ("Closing;"); }
);
1381 f
.FormClosing
+= new FormClosingEventHandler (delegate (Object obj
, FormClosingEventArgs e
) { events += string.Format ("FormClosing [Reason:{0}
- Cancel
:{1}
]", e.CloseReason, e.Cancel); });
1386 Assert.AreEqual ("Closing
;FormClosing
[Reason
:UserClosing
- Cancel
:False
]", events, "A1
");
1390 public void FormClosingEventsCancel ()
1392 // Shows that setting Cancel in Closing flows through to FormClosing
1393 Form f = new Form ();
1394 string events = string.Empty;
1396 f.Closing += new CancelEventHandler (delegate (Object obj, CancelEventArgs e) { events += ("Closing;"); e.Cancel = true; });
1397 f.FormClosing += new FormClosingEventHandler (delegate (Object obj, FormClosingEventArgs e) { events += string.Format("FormClosing [Reason:{0} - Cancel:{1}]", e
.CloseReason
, e
.Cancel
); e
.Cancel
= false; });
1402 Assert
.AreEqual ("Closing;FormClosing [Reason:UserClosing - Cancel:True]", events
, "A1");
1406 public void FormClosedEvents ()
1409 Form f
= new Form ();
1410 string events
= string.Empty
;
1412 f
.Closed
+= new EventHandler (delegate (Object obj
, EventArgs e
) { events += ("Closed;"); }
);
1413 f
.FormClosed
+= new FormClosedEventHandler (delegate (Object obj
, FormClosedEventArgs e
) { events += string.Format ("FormClosed [Reason:{0}
]", e.CloseReason); });
1418 Assert.AreEqual ("Closed
;FormClosed
[Reason
:UserClosing
]", events, "A1
");
1422 public void ShowWithOwner ()
1424 Form f = new Form ();
1425 Button b = new Button ();
1428 Form f2 = new Form ();
1432 Assert.AreSame (f, f2.Owner, "A1
");
1437 Assert.AreSame (f, f2.Owner, "A2
");
1439 Button b2 = new Button ();
1443 Assert.AreEqual (null, f2.Owner, "A3
");
1447 Assert.AreEqual (null, f2.Owner, "A4
");
1451 [ExpectedException (typeof (InvalidOperationException))]
1452 public void ShowWithOwnerIOE ()
1454 Form f = new Form ();
1458 [Test] // Bug #79959, #80574, #80791
1459 [Category ("NotWorking
")]
1460 public void BehaviorResizeOnBorderStyleChanged ()
1462 // Marked NotWorking because the ClientSize is dependent on the WM.
1463 // The values below match XP Luna to make sure our behavior is the same.
1464 Form f = new Form ();
1465 f.ShowInTaskbar = false;
1468 Assert.AreEqual (true, f.IsHandleCreated, "A0
");
1470 Assert.AreEqual (new Size (300, 300), f.Size, "A1
");
1471 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A2
");
1473 f.FormBorderStyle = FormBorderStyle.Fixed3D;
1474 Assert.AreEqual (new Size (302, 302), f.Size, "A3
");
1475 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4
");
1477 f.FormBorderStyle = FormBorderStyle.FixedDialog;
1478 Assert.AreEqual (new Size (298, 298), f.Size, "A5
");
1479 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A6
");
1481 f.FormBorderStyle = FormBorderStyle.FixedSingle;
1482 Assert.AreEqual (new Size (298, 298), f.Size, "A7
");
1483 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A8
");
1485 f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
1486 Assert.AreEqual (new Size (298, 290), f.Size, "A9
");
1487 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A0
");
1489 f.FormBorderStyle = FormBorderStyle.None;
1490 Assert.AreEqual (new Size (292, 266), f.Size, "A11
");
1491 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A12
");
1493 f.FormBorderStyle = FormBorderStyle.SizableToolWindow;
1494 Assert.AreEqual (new Size (300, 292), f.Size, "A13
");
1495 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A14
");
1497 f.FormBorderStyle = FormBorderStyle.Sizable;
1498 Assert.AreEqual (new Size (300, 300), f.Size, "A15
");
1499 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A16
");
1504 [Test] // Bug #80574, #80791
1505 [Category ("NotWorking
")]
1506 public void BehaviorResizeOnBorderStyleChangedNotVisible ()
1508 // Marked NotWorking because the ClientSize is dependent on the WM.
1509 // The values below match XP Luna to make sure our behavior is the same.
1510 Form f = new Form ();
1511 f.ShowInTaskbar = false;
1513 Assert.AreEqual (false, f.IsHandleCreated, "A0
");
1515 Assert.AreEqual (new Size (300, 300), f.Size, "A1
");
1516 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A2
");
1518 f.FormBorderStyle = FormBorderStyle.Fixed3D;
1519 Assert.AreEqual (new Size (300, 300), f.Size, "A3
");
1520 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4
");
1522 f.FormBorderStyle = FormBorderStyle.FixedDialog;
1523 Assert.AreEqual (new Size (300, 300), f.Size, "A5
");
1524 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A6
");
1526 f.FormBorderStyle = FormBorderStyle.FixedSingle;
1527 Assert.AreEqual (new Size (300, 300), f.Size, "A7
");
1528 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A8
");
1530 f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
1531 Assert.AreEqual (new Size (300, 300), f.Size, "A9
");
1532 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A0
");
1534 f.FormBorderStyle = FormBorderStyle.None;
1535 Assert.AreEqual (new Size (300, 300), f.Size, "A11
");
1536 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A12
");
1538 f.FormBorderStyle = FormBorderStyle.SizableToolWindow;
1539 Assert.AreEqual (new Size (300, 300), f.Size, "A13
");
1540 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A14
");
1542 f.FormBorderStyle = FormBorderStyle.Sizable;
1543 Assert.AreEqual (new Size (300, 300), f.Size, "A15
");
1544 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A16
");
1547 [Test] // Bug #80574, #80791
1548 [Category ("NotWorking
")]
1549 public void MoreBehaviorResizeOnBorderStyleChangedNotVisible ()
1551 // Marked NotWorking because the ClientSize is dependent on the WM.
1552 // The values below match XP Luna to make sure our behavior is the same.
1553 Form f = new Form ();
1554 f.ShowInTaskbar = false;
1559 Assert.AreEqual (true, f.IsHandleCreated, "A0
");
1561 f.FormBorderStyle = FormBorderStyle.Sizable;
1562 Assert.AreEqual (new Size (300, 300), f.Size, "A1
");
1563 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A2
");
1564 f.FormBorderStyle = FormBorderStyle.None;
1565 Assert.AreEqual (new Size (292, 266), f.Size, "A3
");
1566 Assert.AreEqual (new Size (292, 266), f.ClientSize, "A4
");
1570 [Test] // Bug #80773
1571 public void DontSetOwnerOnShowDialogException ()
1573 Form f = new Form ();
1574 f.ShowInTaskbar = false;
1576 try { f.ShowDialog (f); }
1579 Assert.AreEqual (null, f.Owner, "H1
");
1582 private class MockForm : Form
1584 public bool CloseOnLoad {
1585 get { return _closeOnLoad; }
1586 set { _closeOnLoad = value; }
1589 public bool VisibleOnLoad {
1590 get { return _visibleOnLoad; }
1593 protected override void OnLoad(EventArgs e) {
1595 _visibleOnLoad = Visible;
1600 private bool _closeOnLoad;
1601 private bool _visibleOnLoad;