using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ErrorTip
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if(textBox1.Text.Length>12||textBox1.Text.Length<6)
{
this.errorProvider1.SetError(this.textBox1,"用户名输入错误");
DialogResult ReturnDlg = MessageBox.Show(this,"用户名输入错误,是否重试?","错误提示",MessageBoxButtons.RetryCancel,MessageBoxIcon.Question);
switch(ReturnDlg)
{
case DialogResult.Retry:
this.textBox1.Text="";
break;
case DialogResult.Cancel:
break;
}
}
else if (textBox2.Text.Length > 12 || textBox2.Text.Length < 6)
{
this.errorProvider1.SetError(this.textBox2, "密码输入错误");
DialogResult ReturnDlg = MessageBox.Show(this, "密码输入错误,是否重试?", "错误提示", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question);
switch (ReturnDlg)
{
case DialogResult.Retry:
this.textBox2.Text = "";
break;
case DialogResult.Cancel:
break;
}
}
else if (textBox3.Text.Length != textBox2.Text.Length)
{
this.errorProvider1.SetError(this.textBox1, "两次输入密码不一致");
DialogResult ReturnDlg = MessageBox.Show(this, "两次输入密码不一致,是否重试?", "错误提示", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question);
switch (ReturnDlg)
{
case DialogResult.Retry:
this.textBox3.Text = "";
break;
case DialogResult.Cancel:
break;
}
}
else
MessageBox.Show("输入正确,请稍等...", "信息验证");
}
}
}
总结:1.从上面程序看出,窗体form1是继承自form的一个子类,本身是类,其中的事件可以看成是方法,可以在其中定义变量等;
2.this指针指向当前类或者对象,在windows编程中指向当前窗体;
3.if
if
if
else语句不能正确表示当输入正确时返回messagebox消息;必须用到:
if
else if
else if
else语句;
4.DialogResult指定标示符以返回对话框的返回值;
加油,蝈蝈
老婆在等你呢,嘿嘿