选择类控件-----ComboBox控件---CheckBox控件
2017-03-01 21:04
337 查看
选择类控件--ComboBox控件---CheckBox控件
1、ComboBox控件
(1)属性DropDownStyle:获取或设置指定组合框样式的值(有3个值)。
Simple:使ComboBox控件的列表部分总是可见的。
DropDown:DropDownStyle属性的默认值,只有单击右侧箭头才能显示列表部分。
DropDownList:用户不能编辑ComboBox控件文本部分,呈现下拉框的样式。
实例演示1:
为Form1窗体添加Load事件,其代码为Form1.cs:
运行结果:
实例演示2:
为Form1窗体添加Load事件,为ComboBox控件添加SelectedValueChanged事件,其代码为Form1.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 选择类控件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;//设置DropDownStyle属性,设为下拉列表样式
comboBox1.Items.Add("helloworld");
comboBox1.Items.Add("The second");
comboBox1.Items.Add("come on!");
}
private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
label1.Text = comboBox1.Text;
}
}
}
运行结果:
实例演示3:
将comboBox名字改为num_s,为Form1窗体添加Load事件.
为ComboBox控件添加SelectedValueChanged事件,其代码为Form1.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 选择类控件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
num_s.DropDownStyle = ComboBoxStyle.DropDownList;//设置DropDownStyle属性,设为下拉列表样式
num_s.Items.Add("helloworld");
//波特率
int[] baud = { 115200, 57600, 38400, 28800, 19200, 14400, 9600, 4800, 2400, 1200 };
for (int i = 0; i < 10; i++)
{
num_s.Items.Add(baud[i]); //向控件循环添加数据
}
num_s.SelectedIndex = 7; //默认选择第7项
}
private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
label1.Text = num_s.Text; //label控件显示选中comboBox控件中的内容
}
}
}
运行结果
2、CheckBox控件(1)控件CheckState属性:Checked被选中;Unchecked取消选中状态实例1:
为控件checkBox1添加Click事件,Form1.cs代码为:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 选择类控件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void checkBox1_Click(object sender, EventArgs e)
{
if (checkBox1.CheckState==CheckState.Checked) //被选中
{
MessageBox.Show("CheckBox控件被选中");
}
else //取消选中
{
MessageBox.Show("CheckBox控件被取消");
}
}
}
}
效果:
1、ComboBox控件
(1)属性DropDownStyle:获取或设置指定组合框样式的值(有3个值)。
Simple:使ComboBox控件的列表部分总是可见的。
DropDown:DropDownStyle属性的默认值,只有单击右侧箭头才能显示列表部分。
DropDownList:用户不能编辑ComboBox控件文本部分,呈现下拉框的样式。
实例演示1:
为Form1窗体添加Load事件,其代码为Form1.cs:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace 选择类控件 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { comboBox1.DropDownStyle = ComboBoxStyle.DropDownList; //设置DropDownStyle属性,设为下拉列表样式 comboBox1.Items.Add("helloworld"); //向控件添加数据 comboBox1.Items.Add("The second"); comboBox1.Items.Add("come on!"); } }}
运行结果:
实例演示2:
为Form1窗体添加Load事件,为ComboBox控件添加SelectedValueChanged事件,其代码为Form1.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 选择类控件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;//设置DropDownStyle属性,设为下拉列表样式
comboBox1.Items.Add("helloworld");
comboBox1.Items.Add("The second");
comboBox1.Items.Add("come on!");
}
private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
label1.Text = comboBox1.Text;
}
}
}
运行结果:
实例演示3:
将comboBox名字改为num_s,为Form1窗体添加Load事件.
为ComboBox控件添加SelectedValueChanged事件,其代码为Form1.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 选择类控件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
num_s.DropDownStyle = ComboBoxStyle.DropDownList;//设置DropDownStyle属性,设为下拉列表样式
num_s.Items.Add("helloworld");
//波特率
int[] baud = { 115200, 57600, 38400, 28800, 19200, 14400, 9600, 4800, 2400, 1200 };
for (int i = 0; i < 10; i++)
{
num_s.Items.Add(baud[i]); //向控件循环添加数据
}
num_s.SelectedIndex = 7; //默认选择第7项
}
private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
label1.Text = num_s.Text; //label控件显示选中comboBox控件中的内容
}
}
}
运行结果
2、CheckBox控件(1)控件CheckState属性:Checked被选中;Unchecked取消选中状态实例1:
为控件checkBox1添加Click事件,Form1.cs代码为:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 选择类控件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void checkBox1_Click(object sender, EventArgs e)
{
if (checkBox1.CheckState==CheckState.Checked) //被选中
{
MessageBox.Show("CheckBox控件被选中");
}
else //取消选中
{
MessageBox.Show("CheckBox控件被取消");
}
}
}
}
效果:
相关文章推荐
- VC++ VS2010 MFC 配合串口控件MSCOMM 复选框CheckBox 下拉ComboBox来选择打开串口端口
- 选择DataGrid中的CheckBox控件后该行背景变色
- Study Silverlight《控件之Border, Button, Calendar, Canvas, CheckBox, ComboBox 》
- winform中为ComboBox控件添加“请选择”或“全部”选项
- winform中为ComboBox控件添加“请选择”或“全部”选项
- NetAdvantage UltraWinGrid.UltraGrid控件中使用checkbox选择框
- MFC 控件下拉选择和输入的 ComboBox使用
- Ext.Net中CheckboxSelectionModel的动态隐藏(显示),一定条件下的隐藏(不让选择),获得多选栏位的信息,及后台控件的动态创建
- 选择DataGrid中的CheckBox控件后该行背景变色
- BootStrap表单控件之复选框checkbox和单选择按钮radio
- GridView控件的选择功能,代码实现CheckBox控件的全选、反选以及取消
- Ext.Net Combobox控件 多项选择的变通实现方式
- combobox和textbox中输入数据为非数字leave时的公用事件,只需要在控件的leave事件中选择本事件即可
- VC comboBox控件 关于下拉时鼠标选择时
- GridView控件中添加CheckBox控件,并且实现选择、全选和反选
- QTP测试.NET程序的时候,ComboBox下拉框控件选择后,运行时对象不可见解决方案
- JQuery实现下拉框的选择 与当CheckBox为服务器控件时如何获取值的操作,实现全选与删除
- TreeView 控件 Checkbox 级联选择
- CheckBox_选择框控件(1)
- 控件定位学习:radio、checkbox、ComboBox