Пример #1
0
        public void GetNextControl_NestedControls()
        {
            // - Form
            //   - Button 1
            //   - Panel 1  (Panels are not selectable and are not IContainerControl
            //     - Button 2
            //   - UserControl 1  (UserControls are selectable and is IContainerControl)
            //     - Button 3
            //   - Button 4

            var form = new Form();
            var f    = new ControlAdapter(form);

            var b1 = new Button {
                Text = "Button 1"
            };
            var b2 = new Button {
                Text = "Button 2"
            };
            var b3 = new Button {
                Text = "Button 3"
            };
            var b4 = new Button {
                Text = "Button 4", Top = 90
            };

            f.Controls.Add(b1);

            var p1 = new Panel {
                Text = "Panel 1", Top = 30, Height = 30
            };

            p1.Controls.Add(b2);
            f.Controls.Add(p1);

            var uc1 = new UserControl {
                Text = "UserControl 1", Top = 60, Height = 30
            };

            uc1.Controls.Add(b3);
            f.Controls.Add(uc1);

            f.Controls.Add(b4);

            // Button 1 as "this"
            Assert.Null(b1.GetNextControl(f, true));
            Assert.Null(b1.GetNextControl(b1, true));
            Assert.Null(b1.GetNextControl(p1, true));
            Assert.Null(b1.GetNextControl(b2, true));
            Assert.Null(b1.GetNextControl(uc1, true));
            Assert.Null(b1.GetNextControl(b3, true));
            Assert.Null(b1.GetNextControl(b4, true));

            // Panel 1 as "this"
            Assert.Equal("Button 2", p1.GetNextControl(f, true).Text);
            Assert.Equal("Button 2", p1.GetNextControl(b1, true).Text);
            Assert.Equal("Button 2", p1.GetNextControl(p1, true).Text);
            Assert.Null(p1.GetNextControl(b2, true));
            Assert.Equal("Button 2", p1.GetNextControl(uc1, true).Text);
            Assert.Equal("Button 2", p1.GetNextControl(b3, true).Text);
            Assert.Equal("Button 2", p1.GetNextControl(b4, true).Text);

            // Form as "this"
            Assert.Equal("Button 1", f.GetNextControl(f, true).Text);
            Assert.Equal("Panel 1", f.GetNextControl(b1, true).Text);
            Assert.Equal("Button 2", f.GetNextControl(p1, true).Text);
            Assert.Equal("UserControl 1", f.GetNextControl(b2, true).Text);
            //Assert.Equal ("Button 4", f.GetNextControl (uc1, true).Text);
            Assert.Equal("Button 4", f.GetNextControl(b3, true).Text);
            Assert.Null(f.GetNextControl(b4, true));
        }