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); }
754 public void ResettingDockToNone ()
756 Form f = new Form ();
757 f.ShowInTaskbar = false;
758 f.ClientSize = new Size (300, 300);
760 Control c = new Control ();
761 c.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
767 f.ClientSize = new Size (350, 350);
769 Assert.IsTrue (c.Left > 0, string.Format ("A1: c.Left ({0}) must be greater than 0", c.Left));
770 Assert.IsTrue (c.Top > 0, string.Format ("A2: c.Top ({0}) must be greater than 0", c.Top));
772 c.Dock = DockStyle.None;
773 Assert.IsTrue (c.Left > 0, string.Format ("A3: c.Left ({0}) must be greater than 0", c.Left));
774 Assert.IsTrue (c.Top > 0, string.Format ("A4: c.Top ({0}) must be greater than 0", c.Top));
776 f.ClientSize = new Size (400, 400);
777 Assert.IsTrue (c.Left > 70, string.Format ("A5: c.Left ({0}) must be greater than 70", c.Left));
778 Assert.IsTrue (c.Top > 70, string.Format ("A6: c.Top ({0}) must be greater than 70", c.Top));
785 public class UndockingTests : TestHelper
787 class TestPanel : Panel {
789 public void InvokeSetBoundsCore ()
791 SetBoundsCore (37, 37, 37, 37, BoundsSpecified.All);
794 public void InvokeUpdateBounds ()
796 UpdateBounds (37, 37, 37, 37);
804 protected override void SetUp () {
806 form.ShowInTaskbar = false;
807 form.Size = new Size (400, 400);
808 panel = new TestPanel ();
809 form.Controls.Add (panel);
814 protected override void TearDown ()
821 public void TestUndockDefaultLocation ()
823 Point loc = panel.Location;
824 panel.Dock = DockStyle.Bottom;
825 panel.Dock = DockStyle.None;
826 Assert.AreEqual (loc, panel.Location);
830 public void TestUndockDefaultLocationVisible ()
833 Point loc = panel.Location;
834 panel.Dock = DockStyle.Bottom;
835 panel.Dock = DockStyle.None;
836 Assert.AreEqual (loc, panel.Location);
840 public void TestUndockExplicitLeft ()
843 panel.Dock = DockStyle.Top;
844 panel.Dock = DockStyle.None;
845 Assert.AreEqual (150, panel.Left);
849 public void TestUndockExplicitTop ()
852 panel.Dock = DockStyle.Top;
853 panel.Dock = DockStyle.None;
854 Assert.AreEqual (150, panel.Top);
858 public void TestUndockExplicitLocation ()
860 panel.Location = new Point (50, 50);
861 Point loc = panel.Location;
862 panel.Dock = DockStyle.Bottom;
863 panel.Dock = DockStyle.None;
864 Assert.AreEqual (loc, panel.Location);
868 public void TestUndockExplicitLeftVisible ()
872 panel.Dock = DockStyle.Top;
873 panel.Dock = DockStyle.None;
874 Assert.AreEqual (150, panel.Left);
878 public void TestUndockExplicitTopVisible ()
882 panel.Dock = DockStyle.Top;
883 panel.Dock = DockStyle.None;
884 Assert.AreEqual (150, panel.Top);
888 public void TestUndockExplicitLocationVisible ()
891 panel.Location = new Point (50, 50);
892 Point loc = panel.Location;
893 panel.Dock = DockStyle.Bottom;
894 panel.Dock = DockStyle.None;
895 Assert.AreEqual (loc, panel.Location);
899 public void TestUndockDefaultSize ()
901 Size sz = panel.Size;
902 panel.Dock = DockStyle.Fill;
903 panel.Dock = DockStyle.None;
904 Assert.AreEqual (sz, panel.Size);
908 public void TestUndockExplicitHeight ()
911 panel.Dock = DockStyle.Left;
912 panel.Dock = DockStyle.None;
913 Assert.AreEqual (50, panel.Height);
917 public void TestUndockExplicitSize ()
919 panel.Size = new Size (50, 50);
920 Size sz = panel.Size;
921 panel.Dock = DockStyle.Fill;
922 panel.Dock = DockStyle.None;
923 Assert.AreEqual (sz, panel.Size);
927 public void TestUndockExplicitWidth ()
930 panel.Dock = DockStyle.Top;
931 panel.Dock = DockStyle.None;
932 Assert.AreEqual (50, panel.Width);
936 public void TestUndockExplicitHeightVisible ()
940 panel.Dock = DockStyle.Left;
941 panel.Dock = DockStyle.None;
942 Assert.AreEqual (50, panel.Height);
946 public void TestUndockExplicitSizeVisible ()
949 panel.Size = new Size (50, 50);
950 Size sz = panel.Size;
951 panel.Dock = DockStyle.Fill;
952 panel.Dock = DockStyle.None;
953 Assert.AreEqual (sz, panel.Size);
957 public void TestUndockExplicitWidthVisible ()
961 panel.Dock = DockStyle.Top;
962 panel.Dock = DockStyle.None;
963 Assert.AreEqual (50, panel.Width);
967 public void TestUndockSetBounds ()
969 panel.SetBounds (50, 50, 50, 50, BoundsSpecified.All);
970 panel.Dock = DockStyle.Top;
971 panel.Dock = DockStyle.None;
972 Assert.AreEqual (50, panel.Height, "Height");
973 Assert.AreEqual (50, panel.Left, "Left");
974 Assert.AreEqual (50, panel.Top, "Top");
975 Assert.AreEqual (50, panel.Width, "Width");
979 public void TestUndockSetBoundsVisible ()
982 panel.SetBounds (50, 50, 50, 50, BoundsSpecified.All);
983 panel.Dock = DockStyle.Top;
984 panel.Dock = DockStyle.None;
985 Assert.AreEqual (50, panel.Height, "Height");
986 Assert.AreEqual (50, panel.Left, "Left");
987 Assert.AreEqual (50, panel.Top, "Top");
988 Assert.AreEqual (50, panel.Width, "Width");
992 public void TestUndockSetBoundsCore ()
994 panel.InvokeSetBoundsCore ();
995 panel.Dock = DockStyle.Top;
996 panel.Dock = DockStyle.None;
997 Assert.AreEqual (37, panel.Height, "Height");
998 Assert.AreEqual (37, panel.Left, "Left");
999 Assert.AreEqual (37, panel.Top, "Top");
1000 Assert.AreEqual (37, panel.Width, "Width");
1004 public void TestUndockSetBoundsCoreVisible ()
1007 panel.InvokeSetBoundsCore ();
1008 panel.Dock = DockStyle.Top;
1009 panel.Dock = DockStyle.None;
1010 Assert.AreEqual (37, panel.Height, "Height");
1011 Assert.AreEqual (37, panel.Left, "Left");
1012 Assert.AreEqual (37, panel.Top, "Top");
1013 Assert.AreEqual (37, panel.Width, "Width");
1017 public void TestUndockUpdateBounds ()
1019 panel.InvokeUpdateBounds ();
1020 panel.Dock = DockStyle.Top;
1021 panel.Dock = DockStyle.None;
1022 Assert.AreEqual (37, panel.Height, "Height");
1023 Assert.AreEqual (37, panel.Left, "Left");
1024 Assert.AreEqual (37, panel.Top, "Top");
1025 Assert.AreEqual (37, panel.Width, "Width");
1029 public void TestUndockUpdateBoundsVisible ()
1032 panel.InvokeUpdateBounds ();
1033 panel.Dock = DockStyle.Top;
1034 panel.Dock = DockStyle.None;
1035 Assert.AreEqual (37, panel.Height, "Height");
1036 Assert.AreEqual (37, panel.Left, "Left");
1037 Assert.AreEqual (37, panel.Top, "Top");
1038 Assert.AreEqual (37, panel.Width, "Width");
1043 public void AutoSizeGrowOnlyControls_ShrinkWhenDocked ()
1045 // For most controls that are AutoSized and support the
1046 // AutoSizeMode property, if they are set to GrowOnly,
1047 // they should not shrink. However, they will shrink
1048 // even in GrowOnly mode if they are docked.
1049 // Button is one exception to this rule.
1050 Form f = new Form ();
1051 f.ClientSize = new Size (300, 300);
1052 f.ShowInTaskbar = false;
1055 List<Type> types = new List<Type> ();
1056 types.Add (typeof (TableLayoutPanel));
1057 types.Add (typeof (FlowLayoutPanel));
1058 types.Add (typeof (ToolStripContentPanel));
1059 types.Add (typeof (Panel));
1060 types.Add (typeof (GroupBox));
1061 types.Add (typeof (UserControl));
1062 foreach (Type t in types) {
1063 Control c = t.GetConstructor (Type.EmptyTypes).Invoke (null) as Control;
1065 t.GetProperty ("AutoSizeMode").SetValue (c, AutoSizeMode.GrowOnly, null);
1066 c.Bounds = new Rectangle (5, 5, 100, 100);
1068 Assert.AreEqual (100, c.Height, "1 " + t.Name);
1069 c.Dock = DockStyle.Top;
1070 Assert.IsFalse (100 == c.Height, "2 " + t.Name);
1071 f.Controls.Remove (c);
1079 public void AutoSizeGrowOnlyButtons_DoNotShrinkWhenDocked ()
1081 // For most controls that are AutoSized and support the
1082 // AutoSizeMode property, if they are set to GrowOnly,
1083 // they should not shrink. However, they will shrink
1084 // even in GrowOnly mode if they are docked.
1085 // Button is one exception to this rule.
1086 Form f = new Form ();
1087 f.ClientSize = new Size (300, 300);
1088 f.ShowInTaskbar = false;
1091 List<Type> types = new List<Type> ();
1092 types.Add (typeof (Button));
1093 foreach (Type t in types) {
1094 Control c = t.GetConstructor (Type.EmptyTypes).Invoke (null) as Control;
1096 t.GetProperty ("AutoSizeMode").SetValue (c, AutoSizeMode.GrowOnly, null);
1097 c.Bounds = new Rectangle (5, 5, 100, 100);
1099 Assert.AreEqual (100, c.Height, "1 " + t.Name);
1100 c.Dock = DockStyle.Top;
1101 Assert.AreEqual (100, c.Height, "2 " + t.Name);
1102 f.Controls.Remove (c);