Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to hide the caret in a TEdit Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
27-Aug-02
Category
VCL-General
Language
Delphi 2.x
Views
107
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			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...

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC