How to move the cursor to the end of the text (Delphi)?

This is my code to populate a TextBox using a function SendMessage:

  C := 'Hey there';
  SendMessage(h1, WM_SETTEXT, 1, Integer(PChar(C)));

Now, how can I move the cursor to the end of the text?

+3
source share
2 answers

If you really want to do this with messages, look:

You also have a full edit link:

http://msdn.microsoft.com/en-us/library/ff485923%28v=VS.85%29.aspx

In the code (without messages) you will do something like this:

Edit1.SelLength := 0;
Edit1.SelStart := 0;   // set caret before first character
...
Edit1.SelStart := 1;   // set caret before second character
...
Edit1.SelStart := Length(Edit1.Text) // set caret after the last character

With messages:

SendMessage(h1, EM_SETSEL, Length(C), Length(C));
+15
source

I think your code is wrong. you must use the parameter "EM_SETSEL". my problem is solved with this code:

  //Set a value for external textbox
  SendMessage(h1, WM_SETTEXT, 0, Integer(PChar(C)));
  //move the cursor to end of the textbox(editbox,field,...)
  SendMessage(h1, EM_SETSEL, length(C), length(C));

, :)

+1

Source: https://habr.com/ru/post/1768547/