Mega Code Archive

 
Categories / Delphi / VCL
 

Positioning the caret in an edit control

Question: How do I position the cursor (caret) in an edit or similar type control? Answer: You can use the Delphi SelStart() and SelectLength() methods. Example: procedure TForm1.Button1Click(Sender: TObject); begin Edit1.SetFocus; {Move the caret to the second character} Edit1.SelStart := 2; {Do not select any text} Edit1.SelLength := 0; end;