4.Flow Layout Pane

本视频主要涉及comboBox,checkbox,flowlayoutPanel,等控件的使用。实现了在flowlayoutPanel区域添加多个Button控件,还能调整控件的布局。
1.comboBox
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
          //用switch语句实现combobox变化的响应不同的事件
            switch (comboBox1.Text)
            {
                case"BottomUp":
                    flowLayoutPanel1.FlowDirection = FlowDirection.BottomUp;
                    break;
                case"LeftToRight":
                    flowLayoutPanel1.FlowDirection = FlowDirection.LeftToRight;
                    break;
                case"TopDown":
                    flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
                    break;
                case"RightToLeft":
                    flowLayoutPanel1.FlowDirection = FlowDirection.RightToLeft;
                    break;
            }
        }

2.checkbox

private void checkBox1_CheckedChanged(object sender, EventArgs e)
        { 
            //实现让控件自动换行,全部可见
            if (checkBox1.Checked == true)
                flowLayoutPanel1.WrapContents = true;
            else
                flowLayoutPanel1.WrapContents = false;
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            // 实现滚动条
            if (checkBox2.Checked == true)
                flowLayoutPanel1.AutoScroll = true;
            else
                flowLayoutPanel1.AutoScroll = false;
        }
3.添加按钮
private void button1_Click(object sender, EventArgs e)
        {
            Button newButton = new Button();//定义一个
            newButton.Name = textBox1.Text;
            newButton.Text = textBox2.Text;
            flowLayoutPanel1.Controls.Add(newButton);//实现
        }

posted on 2008-02-22 13:04  爱你的人  阅读(351)  评论(0)    收藏  举报