0

I want to make my program press "End" button (from keyboard) on textBox when I use it for writing .

As example this code is not correct :

private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
   e.KeyCode = Keys.End; //wrong !!
}

Thanks for all..

Na'il
  • 29
  • 9
  • If you want to scroll the box to the end, search for ways [to do that](http://stackoverflow.com/questions/898307/how-do-i-automatically-scroll-to-the-bottom-of-a-multiline-text-box), rather than simulating a key press to do so in a roundabout way. Otherwise, there's also [this](http://stackoverflow.com/questions/3047375/simulating-key-press-c-sharp) post to simulate a keypress. – Rob Feb 15 '17 at 00:27

1 Answers1

0

The code you've suggested above will execute on every key up event, which I think would not be what you want, this would effectively stop a user from easily editing the text in the centre of the text box.

If you just want the cursor to start at the end of the text when the text box received focus, perhaps you chould hook into the GotFocus Event, and then use the SendKeys.Send() method to send the End key.

this.tGID.GotFocus += OnFocus;

private void OnFocus(object sender, EventArgs e)
{
   SendKeys.Send("{END}");
}
Des Horsley
  • 1,858
  • 20
  • 43