delphionclickdelphi-2010textselection

TEdit onclick select all?


How to select all text of a TEdit1 whenever user click on it or click to select some text of it?


Solution

  • How to select all text of a TEdit1 whenever user click on it

    Select Edit1 in the VCL editor and double-click on the OnClick event:

    enter image description here

    procedure TForm13.Edit1Click(Sender: TObject);
    begin
      Edit1.SelectAll;
    end;
    

    You can also link this event to another control like a button.
    Select the button, choose and click on the V arrow to select an event you want to link.

    enter image description here

    Now both Edit1.OnClick and Button1.OnClick link to the same event.