vb.net 教程 3-4 窗体编程 公共控件2 radiobutton & ComboBox
来源:互联网 发布:淘宝分销食品要证吗 编辑:程序博客网 时间:2024/04/29 09:39
5、radiobutton
单选框。与checkbox不同的是,这个控件同时只能选择其中一个。不过有个前提,在同一父容器下,只能选择一个。
属性:
checked:是否被选中
事件:
CheckedChanged:选择状态发生改变
一个简单的例子:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click If RadioButton1.Checked = True Then MessageBox.Show("你是" & RadioButton1.Text) If RadioButton2.Checked = True Then MessageBox.Show("你是" & RadioButton2.Text) If RadioButton3.Checked = True Then MessageBox.Show("你是" & RadioButton3.Text) If RadioButton4.Checked = True Then MessageBox.Show("你是" & RadioButton4.Text) End Sub
运行如下:
6、ComboBox
下拉框,
常用属性:
Items:设置成员,点击属性页面,"Items"后面的按钮,出来字符串集合编辑器,在里面输入下拉框的成员,一个成员占一行:
DropDownStyle:设置下拉框样式
三种样式从左到右分别是
DropDown:通过单击下箭头指定显示列表,用户可以输入新的值。
DropDownList:通过单击下箭头指定显示列表,用户不能输入新的值。
Simple:指定列表始终可见,用户可以输入新的值。
我常用的是DropDownList样式,这样可以把用户的选择限制死,防止用户误输入。
下面的代码重点讲一下items的用法,因为后面还有很多控件都会用到自身的Items
Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load '设置Combox1显示的文本是Combobox1的第一项 ComboBox1.Text = ComboBox1.Items(0) End Sub Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click If txtAddItem.Text.Trim <> "" Then '添加Combobox1的成员,加入到末尾,ComboBox1.Items.Count也会增加1 ComboBox1.Items.Add(txtAddItem.Text) '设置Combox1显示的文本是Combobox1的最后一项 If ComboBox1.Items.Count > 0 Then ComboBox1.Text = ComboBox1.Items(ComboBox1.Items.Count - 1) End If End Sub Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click '删除Combobox1位于当前选择的Index的成员,当然首先确定选择有项目,没有选择的话ComboBox1.SelectedIndex<0 If ComboBox1.SelectedIndex >= 0 Then ComboBox1.Items.RemoveAt(ComboBox1.SelectedIndex) '删除当前选择的成员之后,ComboBox.text是空的,只要成员数量大于0,就把Items(0)显示出来 If ComboBox1.Items.Count > 0 Then ComboBox1.Text = ComboBox1.Items(0) End Sub Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click '清除Combobox1的成员 ComboBox1.Items.Clear() End Sub Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click MessageBox.Show(ComboBox1.Text) End Sub
演示窗体如下:
学习更多vb.net知识,请参看 vb.net 教程 目录
0 0
- vb.net 教程 3-4 窗体编程 公共控件2 radiobutton & ComboBox
- vb.net 教程 3-4 窗体编程 公共控件9 ListView 2
- vb.net 教程 3-4 窗体编程 公共控件10 TreeView 2
- vb.net 教程 3-4 窗体编程 公共控件4 MaskedTextBox
- vb.net 教程 3-4 窗体编程 公共控件9 ListView 4
- vb.net 教程 3-4 窗体编程 公共控件10 TreeView 4
- vb.net 教程 3-4 窗体编程 公共控件3 Listbox & NumericUpDown
- vb.net 教程 3-4 窗体编程 公共控件9 ListView 3
- vb.net 教程 3-4 窗体编程 公共控件10 TreeView 3
- vb.net 教程 3-4 窗体编程 公共控件1 Button、Label、TextBox & CheckBox
- vb.net 教程 3-4 窗体编程 公共控件5 LinkLabel
- vb.net 教程 3-4 窗体编程 公共控件6 PictureBox & ProgressBar
- vb.net 教程 3-4 窗体编程 公共控件7 DateTimePicker & MonthCalendar
- vb.net 教程 3-4 窗体编程 公共控件8 RichTextBox
- vb.net 教程 3-4 窗体编程 公共控件9 ListView 1
- vb.net 教程 3-4 窗体编程 公共控件9 ListView 5
- vb.net 教程 3-4 窗体编程 公共控件9 ListView 6
- vb.net 教程 3-4 窗体编程 公共控件10 TreeView 1
- phpweb后台拿shell简单方法
- Android studio导入HttpClient
- Remove K Digits
- webservice-基础知识
- 简单理解接口回调
- vb.net 教程 3-4 窗体编程 公共控件2 radiobutton & ComboBox
- 关于java多线程
- Cookie的使用
- [Power]待机电流问题,如何查找wakelock
- HTML5实现图片文件异步上传
- 剑指offer-面试题51-数组中重复的数字
- R——R的基本常用操作
- 初识 Ajax
- [后缀自动机 后缀树 虚树] BZOJ 3879 SvT