public void FlowLayoutPanel_SetFlowBreak_Invoke_GetFlowBreakReturnsExpected(bool value)
        {
            using var child   = new Control();
            using var control = new FlowLayoutPanel();
            int layoutCallCount = 0;

            control.Layout += (sender, e) => layoutCallCount++;
            int childLayoutCallCount = 0;

            child.Layout += (sender, e) => childLayoutCallCount++;

            control.SetFlowBreak(child, value);
            Assert.Equal(value, control.GetFlowBreak(child));
            Assert.Equal(0, layoutCallCount);
            Assert.Equal(0, childLayoutCallCount);
            Assert.False(control.IsHandleCreated);
            Assert.False(child.IsHandleCreated);

            // Set same.
            control.SetFlowBreak(child, value);
            Assert.Equal(value, control.GetFlowBreak(child));
            Assert.Equal(0, layoutCallCount);
            Assert.Equal(0, childLayoutCallCount);
            Assert.False(control.IsHandleCreated);
            Assert.False(child.IsHandleCreated);

            // Set different.
            control.SetFlowBreak(child, !value);
            Assert.Equal(!value, control.GetFlowBreak(child));
            Assert.Equal(0, layoutCallCount);
            Assert.Equal(0, childLayoutCallCount);
            Assert.False(control.IsHandleCreated);
            Assert.False(child.IsHandleCreated);
        }
        public void SetFlowBreak_Invoke_GetFlowBreakReturnsExpected(bool value)
        {
            var panel   = new FlowLayoutPanel();
            var control = new Control();

            panel.SetFlowBreak(control, value);
            Assert.Equal(value, panel.GetFlowBreak(control));

            // Set same.
            panel.SetFlowBreak(control, value);
            Assert.Equal(value, panel.GetFlowBreak(control));

            // Set different.
            panel.SetFlowBreak(control, !value);
            Assert.Equal(!value, panel.GetFlowBreak(control));
        }
        public Form2(ref Button button)
        {
            this.button = button;
            InitializeComponent();                      //初始化
            this.Width  = 500;                          //初始宽度
            this.Height = 350;                          //初始高度

            FlowLayoutPanel p1 = new FlowLayoutPanel(); //申请一个新的控件

            p1.Width         = 480;                     //宽度
            p1.Height        = 300;                     //高度
            p1.AutoScroll    = true;                    //增加自动滚动条
            p1.FlowDirection = FlowDirection.TopDown;   //自上而下的流布局
            p1.WrapContents  = false;                   //不截断内容

            for (int i = 1; i <= 2; i++)
            {
                string str = "这是label" + i + ",本文是通过测试FlowLayoutPanel中控件的流布局方式进行显示的。此题是将Label中的内容进行换行显示,并采用垂直方式布局,在布局管理方式的过程中采用流中断机制进行控件内容自动换行,希望能够对学习这个方面的朋友有所帮助!";

                Label l1 = new Label();
                l1.Text     = str;
                l1.AutoSize = true;     //设置AutoSize为可拉伸的

                Label l2 = new Label(); //用这个空白标签产生换行效果
                l2.Text = "";

                p1.Controls.Add(l1); //添加标签进容器
                p1.GetFlowBreak(l1); //获取流中断
                p1.Controls.Add(l2); //将标签添加入容器
                p1.GetFlowBreak(l2); //获取流中断
            }

            for (int n = 1; n <= 3; n++)
            {
                Button b1 = new Button();
                b1.Text     = "这是第" + n + "个Button!";
                b1.AutoSize = true;
                p1.Controls.Add(b1);
                p1.GetFlowBreak(b1);//获取流中断
            }

            this.Controls.Add(p1);
        }
        public void GetFlowBreak_NullControl_ThrowsArgumentNullException()
        {
            var panel = new FlowLayoutPanel();

            Assert.Throws <ArgumentNullException>("control", () => panel.GetFlowBreak(null));
        }
        public void GetFlowBreak_ValidControl_ReturnsExpected()
        {
            var panel = new FlowLayoutPanel();

            Assert.False(panel.GetFlowBreak(new Control()));
        }
        public void FlowLayoutPanel_SetFlowBreak_InvokeControlWithParent_GetFlowBreakReturnsExpected(bool value, int expectedParentLayoutCallCount)
        {
            using var parent = new Control();
            using var child  = new Control
                  {
                      Parent = parent
                  };
            using var control = new FlowLayoutPanel();
            int layoutCallCount = 0;

            control.Layout += (sender, e) => layoutCallCount++;
            int childLayoutCallCount = 0;

            child.Layout += (sender, e) => childLayoutCallCount++;
            int parentLayoutCallCount = 0;

            void parentHandler(object sender, LayoutEventArgs eventArgs)
            {
                Assert.Same(parent, sender);
                Assert.Same(child, eventArgs.AffectedControl);
                Assert.Equal("FlowBreak", eventArgs.AffectedProperty);
                parentLayoutCallCount++;
            }

            parent.Layout += parentHandler;

            try
            {
                control.SetFlowBreak(child, value);
                Assert.Equal(value, control.GetFlowBreak(child));
                Assert.Equal(0, layoutCallCount);
                Assert.Equal(0, childLayoutCallCount);
                Assert.Equal(expectedParentLayoutCallCount, parentLayoutCallCount);
                Assert.False(control.IsHandleCreated);
                Assert.False(child.IsHandleCreated);
                Assert.False(parent.IsHandleCreated);

                // Set same.
                control.SetFlowBreak(child, value);
                Assert.Equal(value, control.GetFlowBreak(child));
                Assert.Equal(0, layoutCallCount);
                Assert.Equal(0, childLayoutCallCount);
                Assert.Equal(expectedParentLayoutCallCount, parentLayoutCallCount);
                Assert.False(control.IsHandleCreated);
                Assert.False(child.IsHandleCreated);
                Assert.False(parent.IsHandleCreated);

                // Set different.
                control.SetFlowBreak(child, !value);
                Assert.Equal(!value, control.GetFlowBreak(child));
                Assert.Equal(0, layoutCallCount);
                Assert.Equal(0, childLayoutCallCount);
                Assert.Equal(expectedParentLayoutCallCount + 1, parentLayoutCallCount);
                Assert.False(control.IsHandleCreated);
                Assert.False(child.IsHandleCreated);
                Assert.False(parent.IsHandleCreated);
            }
            finally
            {
                parent.Layout -= parentHandler;
            }
        }
 public void FlowLayoutPanel_GetFlowBreak_NullControl_ThrowsArgumentNullException()
 {
     using var control = new FlowLayoutPanel();
     Assert.Throws <ArgumentNullException>("control", () => control.GetFlowBreak(null));
 }
 public void FlowLayoutPanel_GetFlowBreak_InvokeValidControl_ReturnsExpected()
 {
     using var child   = new Control();
     using var control = new FlowLayoutPanel();
     Assert.False(control.GetFlowBreak(child));
 }