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;