select all the text in the textbox c# winform
-
hi to all, i'm trying to select all the text in a textbox control (winform) on the enter event. textBox1.SelectionStart = 0; textBox1.SelectionLength = textBox1.TextLength; when the enter event of the textbox si fired with the tab, the text is selected correctly. but when the enter event of the textbox si fired with the mouse click, no text will be selected in textbox does any body knows why ? if yes can you tell me what the solution is ? best regards and thanks in advance fady sayegh
-
hi to all, i'm trying to select all the text in a textbox control (winform) on the enter event. textBox1.SelectionStart = 0; textBox1.SelectionLength = textBox1.TextLength; when the enter event of the textbox si fired with the tab, the text is selected correctly. but when the enter event of the textbox si fired with the mouse click, no text will be selected in textbox does any body knows why ? if yes can you tell me what the solution is ? best regards and thanks in advance fady sayegh
-
hi to all, i'm trying to select all the text in a textbox control (winform) on the enter event. textBox1.SelectionStart = 0; textBox1.SelectionLength = textBox1.TextLength; when the enter event of the textbox si fired with the tab, the text is selected correctly. but when the enter event of the textbox si fired with the mouse click, no text will be selected in textbox does any body knows why ? if yes can you tell me what the solution is ? best regards and thanks in advance fady sayegh
The MouseClick event happens after the Enter event. This is so that the user can click where they want the cursor to be positioned. Try placing your code in the MouseClick event. ---------- There go my people. I must find out where they are going so I can lead them. - Alexander Ledru-Rollin
-
hi to all, i'm trying to select all the text in a textbox control (winform) on the enter event. textBox1.SelectionStart = 0; textBox1.SelectionLength = textBox1.TextLength; when the enter event of the textbox si fired with the tab, the text is selected correctly. but when the enter event of the textbox si fired with the mouse click, no text will be selected in textbox does any body knows why ? if yes can you tell me what the solution is ? best regards and thanks in advance fady sayegh
You can postpone the text selection until after the mouse event processing occurs, which ensures that clicking into the TextBox will have the same effect as tabbing into it.
private void textBox1_Enter(object sender, System.EventArgs e)
{
this.textBox1.BeginInvoke( new MethodInvoker( this.textBox1.SelectAll ) );
}Josh
-
You can postpone the text selection until after the mouse event processing occurs, which ensures that clicking into the TextBox will have the same effect as tabbing into it.
private void textBox1_Enter(object sender, System.EventArgs e)
{
this.textBox1.BeginInvoke( new MethodInvoker( this.textBox1.SelectAll ) );
}Josh
thanks josh, it works.
-
hi to all, i'm trying to select all the text in a textbox control (winform) on the enter event. textBox1.SelectionStart = 0; textBox1.SelectionLength = textBox1.TextLength; when the enter event of the textbox si fired with the tab, the text is selected correctly. but when the enter event of the textbox si fired with the mouse click, no text will be selected in textbox does any body knows why ? if yes can you tell me what the solution is ? best regards and thanks in advance fady sayegh
X| X| X| lots of frustration and angst!!! I have the answer for you...just solved it in my game I'm writing. Unfortunately my machine died last night (and is now on the curb for trash pickup) and the answer is sitting on my couch in the drive cage!!! I had to tinker with things a bit but I did get it to work. Ahhh I remember now....
private void myTextbox_Enter( object sender, MouseEventArgs args )
{
myTextBox.SelectAll();
}That should do it for you. Darn inconsistant behaviour!!