3 using System.Windows.Forms;
7 using System.Collections.Generic;
9 namespace MonoTests.System.Windows.Forms
12 public class DefaultLayoutTest : TestHelper
15 LayoutEventArgs most_recent_args;
17 void p_Layout (object sender, LayoutEventArgs e)
24 public void AnchorLayoutEvents ()
34 p.Layout += new LayoutEventHandler (p_Layout);
36 /* set the button's anchor to something different */
37 b.Anchor = AnchorStyles.Bottom;
38 Assert.AreEqual (1, event_count, "1");
39 Assert.AreEqual ("Anchor", most_recent_args.AffectedProperty, "2");
41 /* reset it to something new with the panel's layout suspended */
44 b.Anchor = AnchorStyles.Top;
45 Assert.AreEqual (0, event_count, "3");
47 Assert.AreEqual (1, event_count, "4");
48 Assert.AreEqual (null, most_recent_args.AffectedProperty, "5");
50 /* with the anchor style set to something, resize the parent */
52 p.Size = new Size (500, 500);
53 Assert.AreEqual (1, event_count, "6");
54 Assert.AreEqual ("Bounds", most_recent_args.AffectedProperty, "7");
56 /* now try it with layout suspended */
59 p.Size = new Size (400, 400);
60 Assert.AreEqual (0, event_count, "8");
62 Assert.AreEqual (1, event_count, "9");
63 Assert.AreEqual (null, most_recent_args.AffectedProperty, "10");
65 /* with the anchor style set to something, resize the child */
67 b.Size = new Size (100, 100);
68 Assert.AreEqual (1, event_count, "11");
69 Assert.AreEqual ("Bounds", most_recent_args.AffectedProperty, "12");
71 /* and again with layout suspended */
74 b.Size = new Size (200, 200);
75 Assert.AreEqual (0, event_count, "13");
77 Assert.AreEqual (1, event_count, "14");
78 Assert.AreEqual (null, most_recent_args.AffectedProperty, "15");
82 public void AnchorTopLeftTest ()
85 f.ShowInTaskbar = false;
87 f.Size = new Size (200, 200);
89 Button b = new Button ();
90 b.Size = new Size (100, 100);
91 b.Anchor = AnchorStyles.Top | AnchorStyles.Left;
95 Assert.AreEqual (0, b.Left, "1");
96 Assert.AreEqual (0, b.Top, "2");
97 f.Size = new Size (300, 300);
99 Assert.AreEqual (0, b.Left, "3");
100 Assert.AreEqual (0, b.Top, "4");
106 public void AnchorTopRightTest ()
108 Form f = new Form ();
109 f.ShowInTaskbar = false;
111 f.Size = new Size (200, 200);
113 Button b = new Button ();
114 b.Size = new Size (100, 100);
115 b.Anchor = AnchorStyles.Top | AnchorStyles.Right;
119 Assert.AreEqual (0, b.Left, "1");
120 Assert.AreEqual (0, b.Top, "2");
122 f.Size = new Size (300, 300);
124 Assert.AreEqual (100, b.Left, "3");
125 Assert.AreEqual (0, b.Top, "4");
131 public void AnchorLeftRightTest ()
133 Form f = new Form ();
134 f.ShowInTaskbar = false;
136 f.Size = new Size (200, 200);
138 Button b = new Button ();
139 b.Size = new Size (100, 100);
140 b.Anchor = AnchorStyles.Left | AnchorStyles.Right;
144 Assert.AreEqual (0, b.Left, "1");
145 Assert.AreEqual (100, b.Right, "2");
147 f.Size = new Size (300, 300);
149 Assert.AreEqual (0, b.Left, "3");
150 Assert.AreEqual (200, b.Right, "4");
156 public void AnchorBottomLeftTest ()
158 Form f = new Form ();
159 f.ShowInTaskbar = false;
161 f.Size = new Size (200, 200);
163 Button b = new Button ();
164 b.Size = new Size (100, 100);
165 b.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
169 Assert.AreEqual (0, b.Left, "1");
170 Assert.AreEqual (0, b.Top, "2");
172 f.Size = new Size (300, 300);
174 Assert.AreEqual (0, b.Left, "3");
175 Assert.AreEqual (100, b.Top, "4");
181 public void AnchorBottomRightTest ()
183 Form f = new Form ();
184 f.ShowInTaskbar = false;
186 f.Size = new Size (200, 200);
188 Button b = new Button ();
189 b.Size = new Size (100, 100);
190 b.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
194 Assert.AreEqual (0, b.Left, "1");
195 Assert.AreEqual (0, b.Top, "2");
197 f.Size = new Size (300, 300);
199 Assert.AreEqual (100, b.Left, "3");
200 Assert.AreEqual (100, b.Top, "4");
206 public void AnchorTopBottomTest ()
208 Form f = new Form ();
209 f.ShowInTaskbar = false;
211 f.Size = new Size (200, 200);
213 Button b = new Button ();
214 b.Size = new Size (100, 100);
215 b.Anchor = AnchorStyles.Top | AnchorStyles.Bottom;
219 Assert.AreEqual (0, b.Top, "1");
220 Assert.AreEqual (100, b.Bottom, "2");
222 f.Size = new Size (300, 300);
224 Assert.AreEqual (0, b.Top, "3");
225 Assert.AreEqual (200, b.Bottom, "4");
230 // Unit test version of the test case in bug #80336
232 public void AnchorSuspendLayoutTest ()
234 Form f = new Form ();
235 f.ShowInTaskbar = false;
239 Button b = new Button ();
240 b.Size = new Size (100, 100);
244 f.Size = new Size (200, 200);
246 b.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
248 Assert.AreEqual (0, b.Top, "1");
249 Assert.AreEqual (0, b.Left, "2");
251 f.Size = new Size (300, 300);
253 Assert.AreEqual (0, b.Top, "3");
254 Assert.AreEqual (0, b.Left, "4");
258 Assert.AreEqual (100, b.Top, "5");
259 Assert.AreEqual (100, b.Left, "6");
264 // another variant of AnchorSuspendLayoutTest1, with
265 // the SuspendLayout moved after the Anchor
268 public void AnchorSuspendLayoutTest2 ()
270 Form f = new Form ();
271 f.ShowInTaskbar = false;
273 Button b = new Button ();
274 b.Size = new Size (100, 100);
278 f.Size = new Size (200, 200);
280 b.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
282 Assert.AreEqual (0, b.Top, "1");
283 Assert.AreEqual (0, b.Left, "2");
287 f.Size = new Size (300, 300);
289 Assert.AreEqual (0, b.Top, "3");
290 Assert.AreEqual (0, b.Left, "4");
294 Assert.AreEqual (100, b.Top, "5");
295 Assert.AreEqual (100, b.Left, "6");
300 // yet another variant, this time with no Suspend/Resume.
302 public void AnchorSuspendLayoutTest3 ()
304 Form f = new Form ();
305 f.ShowInTaskbar = false;
307 Button b = new Button ();
308 b.Size = new Size (100, 100);
312 f.Size = new Size (200, 200);
314 b.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
316 Assert.AreEqual (0, b.Top, "1");
317 Assert.AreEqual (0, b.Left, "2");
319 f.Size = new Size (300, 300);
321 Assert.AreEqual (100, b.Top, "5");
322 Assert.AreEqual (100, b.Left, "6");
327 private string event_raised = string.Empty;
330 public void TestAnchorDockInteraction ()
332 Panel p = new Panel ();
333 p.DockChanged += new EventHandler (DockChanged_Handler);
335 Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, p.Anchor, "A1");
336 Assert.AreEqual (DockStyle.None, p.Dock, "A2");
338 p.Dock = DockStyle.Right;
339 Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, p.Anchor, "A3");
340 Assert.AreEqual (DockStyle.Right, p.Dock, "A4");
341 Assert.AreEqual ("DockStyleChanged", event_raised, "A5");
342 event_raised = string.Empty;
344 p.Anchor = AnchorStyles.Bottom;
345 Assert.AreEqual (AnchorStyles.Bottom, p.Anchor, "A6");
346 Assert.AreEqual (DockStyle.None, p.Dock, "A7");
347 Assert.AreEqual (string.Empty, event_raised, "A8");
349 p.Dock = DockStyle.Fill;
350 Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, p.Anchor, "A9");
351 Assert.AreEqual (DockStyle.Fill, p.Dock, "A10");
352 Assert.AreEqual ("DockStyleChanged", event_raised, "A11");
353 event_raised = string.Empty;
355 p.Anchor = AnchorStyles.Top | AnchorStyles.Left;
356 Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, p.Anchor, "A12");
357 Assert.AreEqual (DockStyle.Fill, p.Dock, "A13");
358 Assert.AreEqual (string.Empty, event_raised, "A14");
360 p.Dock = DockStyle.None;
361 Assert.AreEqual (AnchorStyles.Top | AnchorStyles.Left, p.Anchor, "A15");
362 Assert.AreEqual (DockStyle.None, p.Dock, "A16");
363 Assert.AreEqual ("DockStyleChanged", event_raised, "A17");
364 event_raised = string.Empty;
366 p.Anchor = AnchorStyles.Bottom;
367 p.Dock = DockStyle.None;
368 Assert.AreEqual (AnchorStyles.Bottom, p.Anchor, "A18");
369 Assert.AreEqual (DockStyle.None, p.Dock, "A19");
370 Assert.AreEqual (string.Empty, event_raised, "A20");
373 public void DockChanged_Handler (object sender, EventArgs e)
375 event_raised += "DockStyleChanged";
379 [Category ("NotWorking")]
380 public void BehaviorOverriddenDisplayRectangle ()
382 Control c = new Control ();
383 c.Anchor |= AnchorStyles.Bottom;
384 c.Size = new Size (100, 100);
386 Form f = new DisplayRectangleForm ();
388 f.ShowInTaskbar = false;
391 Assert.AreEqual (new Size (100, 100), c.Size, "A1");
396 private class DisplayRectangleForm : Form
398 public override Rectangle DisplayRectangle
400 get { return Rectangle.Empty; }
405 public void AnchoredControlWithZeroWidthAndHeight ()
407 Form f = new Form ();
408 f.ShowInTaskbar = false;
410 Control c = new Control ();
411 c.Anchor = AnchorStyles.Left | AnchorStyles.Right;
414 Assert.AreEqual (new Rectangle (0, 0, 0, 0), c.Bounds, "N1");
418 public void TestNestedControls ()
420 MainForm f = new MainForm ();
421 f.ShowInTaskbar = false;
424 Assert.AreEqual (new Rectangle (210, 212, 75, 23), f._userControl._button2.Bounds, "K1");
430 public void TestNestedControls2 ()
432 MainForm f = new MainForm ();
433 f.ShowInTaskbar = false;
438 f.Size = new Size (10, 10);
441 Assert.AreEqual (new Rectangle (210, 212, 75, 23), f._userControl._button2.Bounds, "K1");
446 private class MainForm : Form
448 public UserControl1 _userControl;
456 _userControl = new UserControl1 ();
457 _userControl.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right);
458 _userControl.BackColor = Color.White;
459 _userControl.Location = new Point (8, 8);
460 _userControl.Size = new Size (288, 238);
461 _userControl.TabIndex = 0;
462 Controls.Add (_userControl);
466 ClientSize = new Size (304, 280);
467 Location = new Point (250, 100);
468 StartPosition = FormStartPosition.Manual;
470 ResumeLayout (false);
474 private class UserControl1 : UserControl
476 private Button _button1;
477 public Button _button2;
479 public UserControl1 ()
485 _button1 = new Button ();
486 _button1.Location = new Point (4, 4);
487 _button1.Size = new Size (75, 23);
488 _button1.TabIndex = 0;
489 _button1.Text = "Button1";
490 Controls.Add (_button1);
494 _button2 = new Button ();
495 _button2.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
496 _button2.Location = new Point (210, 212);
497 _button2.Size = new Size (75, 23);
498 _button2.TabIndex = 1;
499 _button2.Text = "Button2";
500 Controls.Add (_button2);
504 BackColor = Color.White;
505 ClientSize = new Size (288, 238);
506 ResumeLayout (false);
512 public void TestDockFillWithPadding ()
514 Form f = new Form ();
515 f.ShowInTaskbar = false;
516 f.Padding = new Padding (15, 15, 15, 15);
518 Control c = new Control ();
519 c.Dock = DockStyle.Fill;
523 Assert.AreEqual (new Size (f.ClientSize.Width - 30, f.ClientSize.Height - 30), c.Size, "K1");
530 public void Bug82762 ()
532 if (TestHelper.RunningOnUnix)
533 Assert.Ignore ("WM Size dependent");
535 Form f = new Form ();
536 f.ShowInTaskbar = false;
538 Button b = new Button ();
539 b.Size = new Size (100, 100);
540 b.Anchor = AnchorStyles.None;
545 Assert.AreEqual (new Rectangle (0, 0, 100, 100), b.Bounds, "A1");
547 f.ClientSize = new Size (600, 600);
549 Assert.AreEqual (new Rectangle (158, 168, 100, 100), b.Bounds, "A2");
556 public void Bug82805 ()
558 Control c1 = new Control ();
559 c1.Size = new Size (100, 100);
560 Control c2 = new Control ();
561 c2.Size = new Size (100, 100);
564 c1.Anchor = AnchorStyles.Left | AnchorStyles.Right;
565 c2.Controls.Add (c1);
566 c2.Size = new Size (200, 200);
569 Assert.AreEqual (200, c1.Width, "A1");
574 public void DockedAutoSizeControls ()
576 Form f = new Form ();
577 f.ShowInTaskbar = false;
579 Button b = new Button ();
582 b.AutoSizeMode = AutoSizeMode.GrowAndShrink;
584 b.Dock = DockStyle.Left;
590 Assert.Fail ("button should be less than 200 width: actual {0}", b.Width);
598 public void NestedControls ()
600 Form f = new Form ();
601 f.ShowInTaskbar = false;
603 MyUserControl c = new MyUserControl ();
604 c.Dock = DockStyle.Fill;
605 c.Size = new Size (500, 500);
609 f.ClientSize = new Size (500, 500);
610 f.ResumeLayout (false);
614 Assert.AreEqual (new Size (600, 600), c.lv.Size, "I1");
618 private class MyUserControl : UserControl
622 public MyUserControl ()
624 lv = new ListView ();
626 lv.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
627 lv.Size = new Size (300, 300);
630 Size = new Size (200, 200);
631 ResumeLayout (false);
637 public class DockingTests : TestHelper
645 protected override void SetUp () {
647 form.ShowInTaskbar = false;
648 form.Size = new Size (400, 400);
649 panel = new Panel ();
650 form.Controls.Add (panel);
656 protected override void TearDown () {
661 void IncrementEventCount (object o, EventArgs args)
667 public void TestDockSizeChangedEvent ()
669 panel.SizeChanged += new EventHandler (IncrementEventCount);
670 panel.Dock = DockStyle.Bottom;
671 Assert.AreEqual (1, event_count);
675 public void TestDockLocationChangedEvent ()
677 panel.LocationChanged += new EventHandler (IncrementEventCount);
678 panel.Dock = DockStyle.Bottom;
679 Assert.AreEqual (1, event_count);
683 public void TestDockFillFirst ()
685 Form f = new Form ();
686 f.ShowInTaskbar = false;
688 Panel b1 = new Panel ();
689 Panel b2 = new Panel ();
691 b1.Dock = DockStyle.Fill;
692 b2.Dock = DockStyle.Left;
698 Assert.AreEqual (new Rectangle (b2.Width, 0, f.ClientRectangle.Width - b2.Width, f.ClientRectangle.Height), b1.Bounds, "A1");
699 Assert.AreEqual (new Rectangle (0, 0, 200, f.ClientRectangle.Height), b2.Bounds, "A2");
704 public void TestDockFillLast ()
706 Form f = new Form ();
707 f.ShowInTaskbar = false;
709 Panel b1 = new Panel ();
710 Panel b2 = new Panel ();
712 b1.Dock = DockStyle.Fill;
713 b2.Dock = DockStyle.Left;
719 Assert.AreEqual (new Rectangle (0, 0, f.ClientRectangle.Width, f.ClientRectangle.Height), b1.Bounds, "B1");
720 Assert.AreEqual (new Rectangle (0, 0, 200, f.ClientRectangle.Height), b2.Bounds, "B2");
725 public void TestDockingWithCustomDisplayRectangle ()
727 MyControl mc = new MyControl ();
728 mc.Size = new Size (200, 200);
730 Control c = new Control ();
731 c.Dock = DockStyle.Fill;
735 Form f = new Form ();
736 f.ShowInTaskbar = false;
741 Assert.AreEqual (new Point (20, 20), c.Location, "A1");
742 Assert.AreEqual (new Size (160, 160), c.Size, "A2");
747 private class MyControl : Control
749 public override Rectangle DisplayRectangle {
750 get { return new Rectangle (20, 20, this.Width - 40, this.Height - 40); }
756 public void DockingPreferredSize ()
758 Form f = new Form ();
759 f.ShowInTaskbar = false;
760 f.ClientSize = new Size (300, 300);
763 c1.Size = new Size (100, 100);
764 c1.Dock = DockStyle.Left;
769 Assert.AreEqual (new Size (100, 300), c1.Size, "A1");
773 c2.Size = new Size (100, 100);
774 c2.Dock = DockStyle.Left;
777 Assert.AreEqual (new Size (100, 300), c1.Size, "A2");
782 private class C1 : Panel
784 public override Size GetPreferredSize (Size proposedSize)
786 Console.WriteLine ("HOYO!");
787 return new Size (200, 200);
791 private class C2 : Panel
793 public override Size GetPreferredSize (Size proposedSize)
801 public void ResettingDockToNone ()
803 Form f = new Form ();
804 f.ShowInTaskbar = false;
805 f.ClientSize = new Size (300, 300);
807 Control c = new Control ();
808 c.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
814 f.ClientSize = new Size (350, 350);
816 Assert.IsTrue (c.Left > 0, string.Format ("A1: c.Left ({0}) must be greater than 0", c.Left));
817 Assert.IsTrue (c.Top > 0, string.Format ("A2: c.Top ({0}) must be greater than 0", c.Top));
819 c.Dock = DockStyle.None;
820 Assert.IsTrue (c.Left > 0, string.Format ("A3: c.Left ({0}) must be greater than 0", c.Left));
821 Assert.IsTrue (c.Top > 0, string.Format ("A4: c.Top ({0}) must be greater than 0", c.Top));
823 f.ClientSize = new Size (400, 400);
824 Assert.IsTrue (c.Left > 70, string.Format ("A5: c.Left ({0}) must be greater than 70", c.Left));
825 Assert.IsTrue (c.Top > 70, string.Format ("A6: c.Top ({0}) must be greater than 70", c.Top));
832 public class UndockingTests : TestHelper
834 class TestPanel : Panel {
836 public void InvokeSetBoundsCore ()
838 SetBoundsCore (37, 37, 37, 37, BoundsSpecified.All);
841 public void InvokeUpdateBounds ()
843 UpdateBounds (37, 37, 37, 37);
851 protected override void SetUp () {
853 form.ShowInTaskbar = false;
854 form.Size = new Size (400, 400);
855 panel = new TestPanel ();
856 form.Controls.Add (panel);
861 protected override void TearDown ()
868 public void TestUndockDefaultLocation ()
870 Point loc = panel.Location;
871 panel.Dock = DockStyle.Bottom;
872 panel.Dock = DockStyle.None;
873 Assert.AreEqual (loc, panel.Location);
877 public void TestUndockDefaultLocationVisible ()
880 Point loc = panel.Location;
881 panel.Dock = DockStyle.Bottom;
882 panel.Dock = DockStyle.None;
883 Assert.AreEqual (loc, panel.Location);
887 public void TestUndockExplicitLeft ()
890 panel.Dock = DockStyle.Top;
891 panel.Dock = DockStyle.None;
892 Assert.AreEqual (150, panel.Left);
896 public void TestUndockExplicitTop ()
899 panel.Dock = DockStyle.Top;
900 panel.Dock = DockStyle.None;
901 Assert.AreEqual (150, panel.Top);
905 public void TestUndockExplicitLocation ()
907 panel.Location = new Point (50, 50);
908 Point loc = panel.Location;
909 panel.Dock = DockStyle.Bottom;
910 panel.Dock = DockStyle.None;
911 Assert.AreEqual (loc, panel.Location);
915 public void TestUndockExplicitLeftVisible ()
919 panel.Dock = DockStyle.Top;
920 panel.Dock = DockStyle.None;
921 Assert.AreEqual (150, panel.Left);
925 public void TestUndockExplicitTopVisible ()
929 panel.Dock = DockStyle.Top;
930 panel.Dock = DockStyle.None;
931 Assert.AreEqual (150, panel.Top);
935 public void TestUndockExplicitLocationVisible ()
938 panel.Location = new Point (50, 50);
939 Point loc = panel.Location;
940 panel.Dock = DockStyle.Bottom;
941 panel.Dock = DockStyle.None;
942 Assert.AreEqual (loc, panel.Location);
946 public void TestUndockDefaultSize ()
948 Size sz = panel.Size;
949 panel.Dock = DockStyle.Fill;
950 panel.Dock = DockStyle.None;
951 Assert.AreEqual (sz, panel.Size);
955 public void TestUndockExplicitHeight ()
958 panel.Dock = DockStyle.Left;
959 panel.Dock = DockStyle.None;
960 Assert.AreEqual (50, panel.Height);
964 public void TestUndockExplicitSize ()
966 panel.Size = new Size (50, 50);
967 Size sz = panel.Size;
968 panel.Dock = DockStyle.Fill;
969 panel.Dock = DockStyle.None;
970 Assert.AreEqual (sz, panel.Size);
974 public void TestUndockExplicitWidth ()
977 panel.Dock = DockStyle.Top;
978 panel.Dock = DockStyle.None;
979 Assert.AreEqual (50, panel.Width);
983 public void TestUndockExplicitHeightVisible ()
987 panel.Dock = DockStyle.Left;
988 panel.Dock = DockStyle.None;
989 Assert.AreEqual (50, panel.Height);
993 public void TestUndockExplicitSizeVisible ()
996 panel.Size = new Size (50, 50);
997 Size sz = panel.Size;
998 panel.Dock = DockStyle.Fill;
999 panel.Dock = DockStyle.None;
1000 Assert.AreEqual (sz, panel.Size);
1004 public void TestUndockExplicitWidthVisible ()
1008 panel.Dock = DockStyle.Top;
1009 panel.Dock = DockStyle.None;
1010 Assert.AreEqual (50, panel.Width);
1014 public void TestUndockSetBounds ()
1016 panel.SetBounds (50, 50, 50, 50, BoundsSpecified.All);
1017 panel.Dock = DockStyle.Top;
1018 panel.Dock = DockStyle.None;
1019 Assert.AreEqual (50, panel.Height, "Height");
1020 Assert.AreEqual (50, panel.Left, "Left");
1021 Assert.AreEqual (50, panel.Top, "Top");
1022 Assert.AreEqual (50, panel.Width, "Width");
1026 public void TestUndockSetBoundsVisible ()
1029 panel.SetBounds (50, 50, 50, 50, BoundsSpecified.All);
1030 panel.Dock = DockStyle.Top;
1031 panel.Dock = DockStyle.None;
1032 Assert.AreEqual (50, panel.Height, "Height");
1033 Assert.AreEqual (50, panel.Left, "Left");
1034 Assert.AreEqual (50, panel.Top, "Top");
1035 Assert.AreEqual (50, panel.Width, "Width");
1039 public void TestUndockSetBoundsCore ()
1041 panel.InvokeSetBoundsCore ();
1042 panel.Dock = DockStyle.Top;
1043 panel.Dock = DockStyle.None;
1044 Assert.AreEqual (37, panel.Height, "Height");
1045 Assert.AreEqual (37, panel.Left, "Left");
1046 Assert.AreEqual (37, panel.Top, "Top");
1047 Assert.AreEqual (37, panel.Width, "Width");
1051 public void TestUndockSetBoundsCoreVisible ()
1054 panel.InvokeSetBoundsCore ();
1055 panel.Dock = DockStyle.Top;
1056 panel.Dock = DockStyle.None;
1057 Assert.AreEqual (37, panel.Height, "Height");
1058 Assert.AreEqual (37, panel.Left, "Left");
1059 Assert.AreEqual (37, panel.Top, "Top");
1060 Assert.AreEqual (37, panel.Width, "Width");
1064 public void TestUndockUpdateBounds ()
1066 panel.InvokeUpdateBounds ();
1067 panel.Dock = DockStyle.Top;
1068 panel.Dock = DockStyle.None;
1069 Assert.AreEqual (37, panel.Height, "Height");
1070 Assert.AreEqual (37, panel.Left, "Left");
1071 Assert.AreEqual (37, panel.Top, "Top");
1072 Assert.AreEqual (37, panel.Width, "Width");
1076 public void TestUndockUpdateBoundsVisible ()
1079 panel.InvokeUpdateBounds ();
1080 panel.Dock = DockStyle.Top;
1081 panel.Dock = DockStyle.None;
1082 Assert.AreEqual (37, panel.Height, "Height");
1083 Assert.AreEqual (37, panel.Left, "Left");
1084 Assert.AreEqual (37, panel.Top, "Top");
1085 Assert.AreEqual (37, panel.Width, "Width");
1090 public void AutoSizeGrowOnlyControls_ShrinkWhenDocked ()
1092 // For most controls that are AutoSized and support the
1093 // AutoSizeMode property, if they are set to GrowOnly,
1094 // they should not shrink. However, they will shrink
1095 // even in GrowOnly mode if they are docked.
1096 // Button is one exception to this rule.
1097 Form f = new Form ();
1098 f.ClientSize = new Size (300, 300);
1099 f.ShowInTaskbar = false;
1102 List<Type> types = new List<Type> ();
1103 types.Add (typeof (TableLayoutPanel));
1104 types.Add (typeof (FlowLayoutPanel));
1105 types.Add (typeof (ToolStripContentPanel));
1106 types.Add (typeof (Panel));
1107 types.Add (typeof (GroupBox));
1108 types.Add (typeof (UserControl));
1109 foreach (Type t in types) {
1110 Control c = t.GetConstructor (Type.EmptyTypes).Invoke (null) as Control;
1112 t.GetProperty ("AutoSizeMode").SetValue (c, AutoSizeMode.GrowOnly, null);
1113 c.Bounds = new Rectangle (5, 5, 100, 100);
1115 Assert.AreEqual (100, c.Height, "1 " + t.Name);
1116 c.Dock = DockStyle.Top;
1117 Assert.IsFalse (100 == c.Height, "2 " + t.Name);
1118 f.Controls.Remove (c);
1126 public void AutoSizeGrowOnlyButtons_DoNotShrinkWhenDocked ()
1128 // For most controls that are AutoSized and support the
1129 // AutoSizeMode property, if they are set to GrowOnly,
1130 // they should not shrink. However, they will shrink
1131 // even in GrowOnly mode if they are docked.
1132 // Button is one exception to this rule.
1133 Form f = new Form ();
1134 f.ClientSize = new Size (300, 300);
1135 f.ShowInTaskbar = false;
1138 List<Type> types = new List<Type> ();
1139 types.Add (typeof (Button));
1140 foreach (Type t in types) {
1141 Control c = t.GetConstructor (Type.EmptyTypes).Invoke (null) as Control;
1143 t.GetProperty ("AutoSizeMode").SetValue (c, AutoSizeMode.GrowOnly, null);
1144 c.Bounds = new Rectangle (5, 5, 100, 100);
1146 Assert.AreEqual (100, c.Height, "1 " + t.Name);
1147 c.Dock = DockStyle.Top;
1148 Assert.AreEqual (100, c.Height, "2 " + t.Name);
1149 f.Controls.Remove (c);
1157 public void AnchoredAutoSizedControls_SizeInCorrectDirection ()
1159 Form f = new Form ();
1160 f.ClientSize = new Size (300, 300);
1161 f.ShowInTaskbar = false;
1163 Panel p1 = new Panel ();
1164 p1.Bounds = new Rectangle (150, 150, 0, 0);
1165 p1.Anchor = AnchorStyles.Top | AnchorStyles.Left;
1167 f.Controls.Add (p1);
1169 Panel p2 = new Panel ();
1170 p2.Bounds = new Rectangle (150, 150, 0, 0);
1171 p2.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
1173 f.Controls.Add (p2);
1175 Panel p3 = new Panel ();
1176 p3.Bounds = new Rectangle (150, 150, 0, 0);
1177 p3.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right;
1179 f.Controls.Add (p3);
1181 Panel p4 = new Panel ();
1182 p4.Bounds = new Rectangle (150, 150, 0, 0);
1183 p4.Anchor = AnchorStyles.None;
1185 f.Controls.Add (p4);
1188 // cause the panels to grow
1189 p1.Controls.Add (new TextBox ());
1190 p2.Controls.Add (new TextBox ());
1191 p3.Controls.Add (new TextBox ());
1192 p4.Controls.Add (new TextBox ());
1195 Assert.AreEqual (150, p1.Top, "1");
1196 Assert.AreEqual (150, p1.Left, "2");
1197 Assert.AreEqual (150, p2.Bottom, "3");
1198 Assert.AreEqual (150, p2.Right, "4");
1199 Assert.AreEqual (150, p3.Top, "5");
1200 Assert.AreEqual (150, p3.Left, "6");
1201 Assert.AreEqual (150, p4.Top, "7");
1202 Assert.AreEqual (150, p4.Left, "8");