C# TextBox事件是我们在开发中会碰到的具体的功能需求那么如何使得想要的C# TextBox事件执行呢?那么这里就向你介绍具体的C# TextBox事件演示实例包括需求的实现希望对你有所帮助
C# TextBox事件具体的需求
◆界面要求定义个TEXTBOX分别是姓名地址职业年龄输出内容个BUTTON
◆满足条件
()用户名不能为空
()年龄必须是一个大于或等于的数字
()职业必须是程序员或为空
()地址不能为空
C# TextBox事件实例实现
using System;
using SystemCollectionsGeneric; using SystemComponentModel;
using SystemData;
using SystemDrawing;
using SystemText;
using SystemWindowsForms;
namespace Chapter
{
public partial class Form : Form
{
public Form()
{
InitializeComponent();
thisbuttonEnabled = false;
thistextBoxTag = false;
thistextBoxTag = false;
thistextBoxTag = false;
thistextBoxTag = false;
thistextBoxValidating+= new SystemComponentModelCancelEventHandler( thistextboxEmpty_Validating);
thistextBoxValidating += new SystemComponentModelCancelEventHandler( thistextboxEmpty_Validating);
thistextBoxValidating+= new SystemComponentModelCancelEventHandler( thistextboxOccupation_Validating);
thistextBoxValidating += new SystemComponentModelCancelEventHandler( thistextboxEmpty_Validating);
thistextBoxTextChanged += new SystemEventHandler(thistextbox_TextChanged);
thistextBoxTextChanged += new SystemEventHandler(thistextbox_TextChanged);
thistextBoxTextChanged += new SystemEventHandler(thistextbox_TextChanged);
}
//C# TextBox事件 private void textboxOccupation_Validating( object sender SystemComponentModelCancelEventArgs e)
{
TextBox tb=(TextBox)sender;
if (tbTextCompareTo(Programmer) == ||tbTextLength==)
{
tbTag = true;
tbBackColor = SystemDrawingSystemColorsWindow;
}
else
{
tbTag = false;
tbBackColor = ColorRed;
}
ValidateOk();
}
//C# TextBox事件 private void textboxEmpty_Validating( object sender SystemComponentModelCancelEventArgs e)
{
TextBox tb = (TextBox)sender;
if (tbTextLength == )
{
tbBackColor = ColorRed;
tbTag = false;
}
else
{
tbBackColor = SystemDrawingSystemColorsWindow;
tbTag = true;
}
ValidateOk();
}
private void textboxAge_KeyPress( object sender KeyPressEventArgs e)
{
if ((eKeyChar < || eKeyChar > ) && eKeyChar != )
eHandled = true;
}
private void textbox_TextChanged( object sender SystemEventArgs e)
{
TextBox tb = (TextBox)sender;
if (tbTextLength == && tb!=textBox)
{
tbTag = false; tbBackColor = ColorRed;
}
else if (tb == thistextBox && (tbTextLength != && tbTextCompareTo(Programmer) != ))
{
tbTag = false;
}
//C# TextBox事件 else
{
tbTag = true;
tbBackColor = SystemColorsWindow;
}
ValidateOk();
}
private void ValidateOk()
{
thisbuttonEnabled = ((bool)(thistextBoxTag) && (bool)(thistextBoxTag) && (bool)(thistextBoxTag) && (bool)(thistextBoxTag));
}
private void button_Click( object sender EventArgs e)
{
string output;
//C# TextBox事件
output = Name: + thistextBoxText + ;
output += Address: + thistextBoxText + ;
output += Occupation: + thistextBoxText + ;
output += Age: + thistextBoxText + ;
thistextBoxText = output;
}
}
}
C# TextBox事件实现的具体实例就向你介绍到这里希望对你了解和学习C# TextBox事件有所帮助