I'm attempting to create a TimeCard application for employees to be able track their hours through an application instead of having to write down their hours manually. I have a decent amount of textboxes that i need to check.
First, I want to check if the textbox is clicked it will clear the value that is currently in that textbox.
Second, I want to check the textboxes again, if the user clicks out of the textbox and didn't insert any values(hours) in the textbox(blank textbox) it will automatically return the text back to 0(hours).
I am using the 'MouseClick' property to assign all these textboxes. The first part of mode code works correctly.When a user clicks on the box it clears the 0 text that was there before, but I can't figure out how to return that 0 value. Once the textbox is clicked it clears the textbox and leave it blank.I've seen ways that you can do it one at a time, but i'm trying to learn how to code efficiently. Any guidance and help on this situation would be greatly appreciated. Thank You.
Tools: C# / Visual Studio 2012 / Microsoft SQL 2012
private void MainForm_Load(object sender, EventArgs e)
{
foreach (Control control1 in this.Controls)
{
if (control1 is TextBox)
{
control1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.AllTextBoxes_Click);
}
}
}
//Mouse Click Clear
private void AllTextBoxes_Click(object sender, MouseEventArgs e)
{
if ((sender is TextBox))
{
((TextBox)(sender)).Text = "";
}
}