How to hide caret in Delphi TEdit?

一世执手 提交于 2019-12-23 16:08:29

问题


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?


回答1:


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;



回答2:


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;


来源:https://stackoverflow.com/questions/7659734/how-to-hide-caret-in-delphi-tedit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!