windows窗体控件的学习

来源:互联网 发布:单片机设计师 编辑:程序博客网 时间:2024/05/21 11:03

checkbox 的学习

属性:checked:该值指示复选框是否处于选中状态,

text:与此控件关联的文本

name:获取或设置控件的名称

事件:click:当鼠标单击控件时发生

checkedchanged:checked值发生变化

        private void checkBox1_CheckedChanged(object sender, EventArgs e)        {            if (checkBox1.Checked == true && checkBox2.Checked == true)  //是否为选中状态                textBox3.Text = "我喜欢" + checkBox1.Text + "和" + checkBox2.Text;            else if (checkBox1.Checked == false && checkBox2.Checked == true)                textBox3.Text = "我喜欢" + checkBox2.Text;            else if (checkBox1.Checked == true && checkBox2.Checked == false)                textBox3.Text = "我喜欢" + checkBox1.Text;            else                textBox3.Text = " ";        }        private void checkBox2_CheckedChanged(object sender, EventArgs e)        {            if (checkBox1.Checked == true && checkBox2.Checked == true)                textBox3.Text = "我喜欢" + checkBox1.Text + "和" + checkBox2.Text;            else if (checkBox1.Checked == false && checkBox2.Checked == true)                textBox3.Text = "我喜欢" + checkBox2.Text;            else if (checkBox1.Checked == true && checkBox2.Checked == false)                textBox3.Text = "我喜欢" + checkBox1.Text;            else                textBox3.Text = " ";        }

radiobutton的使用

属性: checked:该值指示是否已选中控件;

text:与此控件关联的文本;

flatstyle:获取或设置按钮控件的平面样式外观

enabled:指示控件是否可以对用户交互作出响应;

parent:指示容器父容器

事件:click:当鼠标击控件时发生

checkedchanged:checked值发生改变时发生;

private void radioButton1_CheckedChanged(object sender, EventArgs e)        {            if (radioButton1.Checked == true)                textBox4.Text = "我很" + radioButton1.Text;        }        private void radioButton2_CheckedChanged(object sender, EventArgs e)        {            if (radioButton2.Checked == true)                textBox4.Text = "我很" + radioButton2.Text;        }

listbox控件:

属性:items:该属性是一个集合,用以存放在列表框中显示的条目;

sorted:控制是否对列表进行排序

事件举例:

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)        {            textBox5.Text = "你喜欢第" + listBox1.SelectedIndex.ToString() + "种颜色" + listBox1.Text;        }


 

原创粉丝点击