开发者

How to hide caret in Delphi TEdit?

开发者 https://www.devze.com 2023-04-10 15:12 出处:网络
I want to remove the caret from a TEdit control in Delphi. I have made the component Enabled := False but the caret still appears.

I want to remove the caret from a TEdit control in Delphi. I have made the component Enabled := False but the caret still appears. My 开发者_运维问答question is how to remove the caret from a disabled TEdit control?


I assume that you mean TEdit control.

The solution is HideCaret function, the only problem is where to call it. The 2 event handlers below worked fine for me:

procedure TForm18.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  HideCaret(Edit1.Handle);
end;

procedure TForm18.Edit1MouseEnter(Sender: TObject);
begin
  HideCaret(Edit1.Handle);
end;


Place a TApplicationEventscontrol on the form and in the OnIdle event, hide the caret, as follows. Set the event to nil so it only fires once.

procedure TFormMain.AppEventsIdle(Sender: TObject; var Done: Boolean);
begin
  AppEvents.OnIdle := nil;
  HideCaret(Memo1.Handle);
end;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号