Author: Tomas Rutkauskas
Does anyone know how I might be able to suppress the text cursor in a TEdit, so
it's not visible?
Answer:
For that you need to call the HideCaret API function after the control has
processed the WM_SETFOCUS message. The OnEnter event is a tad too early for that,
so if you do not want to create a TEdit descendent with an overriden message
handler for WM_SETFOCUS you need to delay the action by posting a message to the
form and have the handler for that message do the HideCaret.
The three edits on this example form share the same OnEnter handler (AllEditEnter),
have ReadOnly = true and AutoSelect = false.
1 unit Unit1;
2
3 interface
4
5 uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, stdctrls, jpeg;
8
9 const
10 UM_HIDECARET = WM_USER + 101;
11 type
12 TUMHideCaret = packed record
13 msg: Cardinal;
14 control: TWinControl;
15 end;
16 type
17 TForm1 = class(TForm)
18 Button1: TButton;
19 Memo1: TMemo;
20 Edit1: TEdit;
21 Edit2: TEdit;
22 Edit3: TEdit;
23 procedure AllEditEnter(Sender: TObject);
24 private
25 { Private declarations }
26 procedure UMHideCaret(var msg: TUMHideCaret); message UM_HIDECARET;
27 public
28 { Public declarations }
29 end;
30
31 var
32 Form1: TForm1;
33
34 implementation
35
36 {$R *.dfm}
37
38 procedure TForm1.AllEditEnter(Sender: TObject);
39 begin
40 PostMessage(handle, UM_HIDECARET, wparam(sender), 0);
41 end;
42
43 procedure TForm1.UMHideCaret(var msg: TUMHideCaret);
44 begin
45 HideCaret(msg.control.Handle);
46 end;
47
48 end.
Of course this is an excellent way to confuse the user, since there will be no indication where the focus is anymore when the user tabs into one of the edits...
|