通过对视频的学习,对winform有了一个大致的了解和认识。。。winform是有多个控件来实现的,控件就是winform中抽象的一些类, 包括button(按钮)文本框(textbox)
标签(label) 单选按钮(Radiobutton)、复选框(CHeckBox)
在这里我们贴上几个简单的代码来让大家对winform有更直观的认识、
实例一、 对email 的分析,将用户输入的email信息进行分割、、
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string email = textBox1.Text;
string[] str = email.Split('@');
if (str.Length != 2)
{
MessageBox.Show("输入的Email地址非法");
return;
}
textBox2.Text = str[0];
textBox3.Text = str[1];
}
private void label2_Click(object sender, EventArgs e)
{
}
}
实例2、、 一个经典的简单的 登陆页面。
public partial class Form1 : Form
{
private int ErrorTimes=0;
public Form1()
{
InitializeComponent();
}
private void btnlogin_Click(object sender, EventArgs e)
{
string username = txtUserName.Text.Trim();
string password = txtPassword.Text.Trim();
if (username == "admin" && password == "888888")
{ MessageBox.Show("登陆成功"); }
else
{
ErrorTimes++;
if (ErrorTimes >= 3)
{
MessageBox.Show("错误次数过多,程序即将退出");
Application.Exit();
}
MessageBox.Show("登录失败");
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}