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?
Asked
Active
Viewed 6,533 times
3

Kromster
- 7,181
- 7
- 63
- 111

Jordan Borisov
- 1,603
- 6
- 34
- 69
2 Answers
8
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;

kludg
- 27,213
- 5
- 67
- 118
-
3Thanks. I've found another solution for this problem. I just set ReadOnly with True. – Jordan Borisov Oct 05 '11 at 10:30
-
2@Jordan That does something else though doesn't it. – David Heffernan Oct 05 '11 at 10:35
-
@DavidHeffernan Yes it does but I want to remove the caret only for make a text box read only without caret when I click it. – Jordan Borisov Oct 05 '11 at 11:15
-
1@user246408 thank you, it works in D7 too. But in tEdit there is no "MouseEnter", only "MouseDown". Has something changed in newer Delphi versions? – ZioBit Jul 12 '14 at 15:04
0
Place a TApplicationEvents
control 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;

Pieter van Wyk
- 2,316
- 9
- 48
- 65