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 create a flat TCheckBox 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 All Versions
Views
54
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I want to inherit the TCheckbox class in order to create a new TCheckBox class that 
is the flat version for TCheckbox. What style to override in order to make it a 
flat checkbox instead of a 3D checkbox?

Answer:

1   { ... }
2   TExCheckBox = class(TCheckBox)
3   private
4     { Private declarations }
5     FFlat: Boolean;
6     FMultiLine: Boolean;
7     FPushLike: Boolean;
8     procedure SetFlat(const Value: Boolean);
9     procedure SetMultiLine(const Value: Boolean);
10    procedure SetPushLike(const Value: Boolean);
11  protected
12    { Protected declarations }
13    procedure CreateParams(var Params: TCreateParams); override;
14  public
15    { Public declarations }
16    constructor Create(AOwner: TComponent); override;
17  published
18    { Published declarations }
19    property Flat: Boolean read FFlat write SetFlat default true;
20    property MultiLine: Boolean read FMultiLine write SetMultiLine default false;
21    property PushLike: Boolean read FPushLike write SetPushLike default false;
22  end;
23  
24  { TExCheckBox }
25  
26  constructor TExCheckBox.Create(AOwner: TComponent);
27  begin
28    FFlat := true;
29    FMultiLine := false;
30    FPushLike := false;
31    inherited Create(AOwner);
32  end;
33  
34  procedure TExCheckBox.CreateParams(var Params: TCreateParams);
35  begin
36    inherited CreateParams(Params);
37    if FFlat then
38      Params.Style := Params.Style or BS_FLAT
39    else
40      Params.Style := Params.Style and not BS_FLAT;
41    if FMultiLine then
42      Params.Style := Params.Style or BS_MULTILINE
43    else
44      Params.Style := Params.Style and not BS_MULTILINE;
45    if FPushLike then
46      Params.Style := Params.Style or BS_PUSHLIKE
47    else
48      Params.Style := Params.Style and not BS_PUSHLIKE;
49  end;
50  
51  procedure TExCheckBox.SetFlat(const Value: Boolean);
52  begin
53    if Value <> FFlat then
54    begin
55      FFlat := Value;
56      RecreateWnd;
57    end;
58  end;
59  
60  procedure TExCheckBox.SetMultiLine(const Value: Boolean);
61  begin
62    if Value <> FMultiLine then
63    begin
64      FMultiLine := Value;
65      RecreateWnd;
66    end;
67  end;
68  
69  procedure TExCheckBox.SetPushLike(const Value: Boolean);
70  begin
71    if Value <> FPushLike then
72    begin
73      FPushLike := Value;
74      RecreateWnd;
75    end;
76  end;


			
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