Windows Develop Bookmark and Share   
 index > Windows Forms General > Alterations to a TextBox
 

Alterations to a TextBox

Hi,

I am working on an application at the moment. Being new to Windows programming I have encountered a small problem, but I'm sure someone knows the answer.

I have a TextBox on a form and have set a property handler to it (using get and set statements). I also have an event setup which executes as I type within the box. It updates an array variable name from the box, but what I don't want to do is execute the last statement in the code below until the user has hit the "Enter" key (or if the user tabs to the next TextBox). How can I do that?

At the moment, with every character change the user makes, the function FileUtilities.TiplocCSVConstructor( ); function executes which renders some data to a CSV file. The time it takes to do this means that the user input gets slowed down with each and every character they type. The CSV file that I currently have is 149Kb in size and I don't want to write it out with every character pressed, but often enough so that the file gets updated frequently on the hard disk/network drive in a semi-realtime fashion!

Thanks.


//*********************************************************************************
// This is the handler for when the user changes a custom station name
//*********************************************************************************
private void Custom_StationNameBox_TextChanged(object sender, EventArgs e)
{
if (StationCodes.sCustom_StationNames != sCustom_StationNameBox)
{
StationCodes.sCustom_StationNames = sCustom_StationNameBox.ToUpper();
}
//This is the line I want to execute only when the user has hit enter ot tabbed to the next TextBox!!!
FileUtilities.TiplocCSVConstructor();
}
Sean Connolly  Wednesday, February 15, 2006 4:59 PM

Hi,

You can use textBox1_KeyPress and textBox1_Leave events to trap the enter and the tab keys e.g.

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)

{

// traps the enter key

if (e.KeyChar == 13)

{

MessageBox.Show("yo");

}

}

private void textBox1_Leave(object sender, EventArgs e)

{

//fires when u hit the tab or leave textbox1

MessageBox.Show("textBox1_Leave");

}

Hope this helps.

Get back in case of any queries.

Regards,

Nasha

Nasha1  Wednesday, February 15, 2006 6:31 PM

Thank You! Thank You! Thank You!

My program speed is where it should be now! The CSV file is only updated on these events now!!!!

Kind Regards,

Sean

Sean Connolly  Thursday, February 16, 2006 9:10 AM

You can use google to search for other answers

Custom Search

More Threads

• Saving the Printer Properties
• something wrong with DateTimePicker and ShowCheckBox
• White line under menu in Vista
• How to change the selected value
• Group policy
• How do I save changes made inside a PropertyGrid?
• How do i pass control to another form in a button click event
• What tools exist for reading binary files
• How to make main form stay when subforms open
• Num Lock