Home > OS >  When typing at the end of the editmask, it will pass the number to the left side until it reaches th
When typing at the end of the editmask, it will pass the number to the left side until it reaches th

Time:12-08

Good afternoon,

I'm doing a project in delphi that uses editmask. I'm using the phone mask. When clicking on edit to write the phone number, it goes to the last field on the right, so it is necessary to go back with the backspace to the beginning of the edit on the left.

i would like to find a way that when the user typed the number in the last field on the right, it was passed to the left. So on until you complete the phone field. It would be possible?

Using an example of what it would look like:

enter image description here

enter image description here

enter image description here

I couldn't think of a way to do it

CodePudding user response:

The component is called TMaskEdit.

Just like anything that bases on TEdit putting the focus onto the control will by default put the text cursor at the end of its content

  • via keyboard, should .AutoSelect be FALSE and
  • via mouse if clicking behind any text (by default the text is aligned to the left).

You should have experienced this with the other components already. If you want the text cursor to always be at a certain position upon focusing the control, then do that in such an event handler:

  • for keyboard use OnEnter:
    procedure TForm1.MaskEdit1Enter(Sender: TObject);
    begin
       (Sender as TMaskEdit).SelStart:= 1;  // Second position
    end;
    
  • and for mouse use OnClick with the same code.

It even works unbound to how the property .AutoSelect is set.

Using Backspace is the worst choice input wise, as it always deletes potential content and needs to be pressed several times to go to the first position. Why not using the Home key instead?

  • Related