How to position the cursor on the right-hand side of a TEdit (Views: 100)


I want to write an Edit component, but I want the cursor to stay on the right when the user types in new characters.


procedure TForm1.Edit1Change(Sender: TObject);
  if IsChanging then
    exit; {Avoid recursion}
  IsChanging := true;
    {Remove the first character}
    Edit1.Text := copy(Edit1.Text, 2, length(Edit1.Text) - 1);
    {And move the cursor to the end of the text}
    Edit1.SelStart := length(Edit1.Text);
    IsChanging := false;

At design time (or in Create), put several spaces as Edit1.Text. They will be replaced one by one with characters typed by the user. IsChanging is a private variable of type boolean.

<< Back to main page