Formating text in textBox
-
I want in my textBox enter characters in the following way:
private void textBox2_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { int i = this.textBox2.SelectionStart; if(i which is mean that every single character which is entered should replace existing character unless the cursor is on the end of the text. This sample code doesn`t work I want. Speaking gennerally I want in my text Box to replace all characters with new entered unless the cursor is on the end of the text. Can anyone help me? -- modified at 9:54 Wednesday 19th April, 2006
-
I want in my textBox enter characters in the following way:
private void textBox2_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { int i = this.textBox2.SelectionStart; if(i which is mean that every single character which is entered should replace existing character unless the cursor is on the end of the text. This sample code doesn`t work I want. Speaking gennerally I want in my text Box to replace all characters with new entered unless the cursor is on the end of the text. Can anyone help me? -- modified at 9:54 Wednesday 19th April, 2006
Try replacing your KeyDown code with: private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { int i = this.textBox1.SelectionStart; if (i < this.textBox1.TextLength) { this.textBox1.SelectAll(); } } When I did this, I had a value in the textbox, keyed a value, and it replaced everything in the text box. When I keyed values at the end, it just added it on. I think that's what you wanted.
-
Try replacing your KeyDown code with: private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { int i = this.textBox1.SelectionStart; if (i < this.textBox1.TextLength) { this.textBox1.SelectAll(); } } When I did this, I had a value in the textbox, keyed a value, and it replaced everything in the text box. When I keyed values at the end, it just added it on. I think that's what you wanted.
I know what you mean, but it isn`t the action I want. I don`t want replace all characters in my textBox but I want replace only that character which is curently selected by the posision of the cursor. For example text: 12345 when the cursor is (for ex.) between 3 and 4 by enter new character a want replace character 4 by new one. This should work like insert key in Microsoft Word. Anyone know the answer?
-
I want in my textBox enter characters in the following way:
private void textBox2_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { int i = this.textBox2.SelectionStart; if(i which is mean that every single character which is entered should replace existing character unless the cursor is on the end of the text. This sample code doesn`t work I want. Speaking gennerally I want in my text Box to replace all characters with new entered unless the cursor is on the end of the text. Can anyone help me? -- modified at 9:54 Wednesday 19th April, 2006
use the Key_Press event instead of the Key_down event...that should work with the same code..