Author: DevASP
Download Source Code : 673_TextboxEvents.zip
In this article I will try to explain how the event occurs of Textbox control. Here I will discuss the very basic events that are very helpful while developing an Application.
To begin
with this application create a windows form and drop two textbox control and
listbox control. Define the following events for the textbox controls:
- Enter Event.
- GotFocus
Event.
- KeyDown Event.
- KeyUp Event.
- KeyPress
Event.
- Leave Event.
- LostFocus
Event.
To check when which occurs I hav used listbox control in which the message
is displayed when the respective event will occur. Code for these Events is as
follows:
Events for the Textbox control1:
void
textBox1_LostFocus(object sender, System.EventArgs e)
{
listBox1.Items.Add("LostFocus
event called of TextBox1");
}
void
textBox1_GotFocus(object sender, System.EventArgs e)
{
listBox1.Items.Add("GotFocus
event called of TextBox1");
}
void
textBox1_Leave(object sender, System.EventArgs e)
{
listBox1.Items.Add("Leave
event called of TextBox1");
}
void
textBox1_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
listBox1.Items.Add("KeyUp
event called of TextBox1");
}
void
textBox1_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
listBox1.Items.Add("KeyPress
event called of TextBox1");
}
void
textBox1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
listBox1.Items.Add("KeyDown
event called of TextBox1");
}
void
textBox1_Enter(object sender, System.EventArgs e)
{
listBox1.Items.Add("Enter
event called of TextBox1");
}
- Events for the Textbox
control2:
void
textBox2_LostFocus(object sender, System.EventArgs e)
{
listBox1.Items.Add("LostFocus
event called of TextBox2");
}
void
textBox2_GotFocus(object sender, System.EventArgs e)
{
listBox1.Items.Add("GotFocus
event called of TextBox2");
}
void
textBox2_Leave(object sender, System.EventArgs e)
{
listBox1.Items.Add("Leave
event called of TextBox2");
}
void
textBox2_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
listBox1.Items.Add("KeyUp
event called of TextBox2");
}
void
textBox2_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
listBox1.Items.Add("KeyPress
event called of TextBox2");
}
void
textBox2_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
listBox1.Items.Add("KeyDown
event called of TextBox2");
}
void
textBox2_Enter(object sender, System.EventArgs e)
{
listBox1.Items.Add("Enter
event called of TextBox2");
}
Note: To check the exact working of controls use Tab button for GotFocus
and LostFocus event and keyboard key stroks for KeyDown, KeyUp, KeyPress
events.