控件
Label 标签:
提供说明性的文字
Name:命名规范-lab+意义
Text:标签显示的文本
textBox文本框
接收或显示用户信息
Name:命名规范-txt+意义
Text:显示的文本
PasswordChar:设置密码框显示的字符
Multiline:设置多行文本框(true)
ReadOnly:设置只读文本框
MaxLength:设置输入的最大字符数
文本框的文本对齐方式:TextAlign
Font:字体(大小、颜色)
怎么获取TextBox内容?
string 变量名 = this.textBox1(控件名).Text;
Button 按钮
提供用户提交或重置信息
Name:命名规范-btn+意义
Text:显示的文本
FlatStyle:改变按钮外观
Click事件:单击事件,在点击按钮时触发(双击按钮即获得该事件)
TransParent:颜色透明
enabled是否启用控件。
RadioButton 单选按钮
Name:命名-rdo+意义
Text:获取或设置单选按钮显示的文本
Checked:判断单选按钮是否被选中(true-选中,false-没选)
GroupBox 分组框:
容器控件,可向分组框中添加其他控件
Name:命名-grp+意义
Text:获取或设置分组框的标题
消息框 MessageBox:
消息框的使用:提示用户信息
1、显示消息框:MessageBox.Show();
1-1、MessageBox.Show("提示文本");
1-2、MessageBox.Show("提示文本","标题");
1-3、MessageBox.Show("提示文本","标题",MessageBoxButtons);
MessageBoxButtons表示显示哪些按钮
1-4、MessageBox.Show("提示文本","标题",MessageBoxButtons,MessageBoxIcon);
MessageBoxIcon表示显示什么图标
2、MessageBox.Show();返回值为DialogResult
2-1、DialogResult-存放消息框的结果--枚举类型
//接收用户选择的结果
DialogResult dr = MessageBox.Show("是否确认退出?", "温馨提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
//根据选择结果进行判断
if (dr == DialogResult.Yes)
{
//关闭当前窗体
this.Close();
}
MessageBox.Show("信息内容","标题",MessageBoxButtons.YesNo(按键),MessageBoxIcon.Error(图标));
下拉组合框(ComboBox):
DropDownStyle:DropDownList禁止用户输入内容
//取值:
string 变量名 = this.comboBox1.Text;
//设置隐藏列和显示列
this.comboBox1.ValueMember = "classId";//隐藏列
this.comboBox1.DisplayMember = "className";//显示列
//添加:
this.comboBox1.Add("值");
//删除:
this.comboBox1.Remove("值");
this.comboBox1.Items.RemoveAt(下标);
//一般不按文本删除。
//文本:
string text = this.comboBox1.Text;
//选中的下标:
int selectIndex = this.comboBox1.SelectedIndex;
this.comboBox1.Items.RemoveAt(selectIndex );
//选中的文本:
string selectText = this.comboBox1.SelectedText;
this.comboBox1.Remove(selectText );
图片:
1.背景图片:
this.BackgroundImage = Image.FromFile(@"路径");
2.PictureBox(相框)和ImageList(图片列表)
//给PictureBox一张图片 图片集 的 第0张
this.pictureBox1.Image = this.imageList1.Images[0];
浙公网安备 33010602011771号