快速业务通道

通过继承实现不同的CheckBox风格

作者 佚名技术 来源 程序设计 浏览 发布时间 2012-06-30

VCL中的TCheckBox控件在选中时显示的是一个“√”,但有的时候需要显示为“×”,下面这段代码是cker写的,实现了这个效果。

// 通过继承实现不同的CheckBox风格

// 代码作者:cker

//---------------------------------------------------------------------------
class TXCheckBox : public TCustomControl
{
private:
bool FDown;
TCheckBoxState FState;
bool FFocused;
TColor FCheckColor;
public:
__fastcall TXCheckBox(TComponent* AOwner);
protected:
void __fastcall Paint();
DYNAMIC void __fastcall MouseDown(TMouseButton Button, TShiftState Shift, int X, int Y);
DYNAMIC void __fastcall MouseUp(TMouseButton Button, TShiftState Shift, int X, int Y);
DYNAMIC void __fastcall MouseMove(TShiftState Shift, int X, int Y);
DYNAMIC void __fastcall KeyDown(Word &Key, TShiftState Shift);
DYNAMIC void __fastcall KeyUp(Word &Key, TShiftState Shift);
void __fastcall SetDown( bool Value);
void __fastcall SetState(TCheckBoxState Value);
void __fastcall SetChecked( bool Value);
bool __fastcall GetChecked();
void __fastcall SetCheckColor(TColor Value);
void __fastcall SetCaption( const TCaption& Value);
TCaption __fastcall GetCaption();
DYNAMIC void __fastcall DoEnter( void);
DYNAMIC void __fastcall DoExit( void);
__published:
__property TCaption Caption = {read=GetCaption, write=SetCaption};
__property TColor CheckColor = {read=FCheckColor, write=SetCheckColor, default=clBlack};
__property bool Checked = {read=GetChecked, write=SetChecked, default= false};
__property bool Down = {read=FDown, write=SetDown, default= false};
__property DragCursor;
__property DragMode;
__property Enabled;
__property Font;
__property ParentFont;
__property PopupMenu;
__property ShowHint;
__property TCheckBoxState State = {read=FState, write=SetState, default=cbUnchecked};
__property TabOrder;
__property TabStop;
__property OnClick;
__property OnDragDrop;
__property OnDragOver;
__property OnEndDrag;
__property OnKeyDown;
__property OnKeyPress;
__property OnKeyUp;
__property OnMouseDown;
__property OnMouseMove;
__property OnMouseUp;
};
__fastcall TXCheckBox::TXCheckBox(TComponent* AOwner):TCustomControl(AOwner)
{
Width = 200;
Height = 20;
ParentColor = false;
Color = clBtnFace;
}
void __fastcall TXCheckBox::Paint()
{
const int BW = 12;
int BL, BT, BR, BB;
int TX, TY, TW, TH;
TRect Rect;
Canvas->Font = Font;
BT = (Height / 2)-(BW / 2);
BB = BT + BW;
BL = 1;
BR = BW + 1;
Canvas->Brush->Color = FDown ? clBtnFace : clWhite;
Canvas->Pen->Width = 1;
Canvas->Pen->Color = clBtnFace;
Canvas->Rectangle(BL, BT, BR, BB);
Canvas->Pen->Color = clBtnShadow;
Canvas->MoveTo(BL, BB);
Canvas->LineTo(BL, BT);
Canvas->LineTo(BR, BT);
Canvas->Pen->Color = clBtnHighlight;
Canvas->LineTo(BR, BB);
Canvas->LineTo(BL, BB);
Canvas->Pen->Color = cl3DDkShadow;
Canvas->MoveTo(BL + 1, BB - 1);
Canvas->LineTo(BL + 1, BT + 1);
Canvas->LineTo(BR - 1, BT + 1);
Canvas->Pen->Color = cl3DLight;
Canvas->LineTo(BR - 1, BB - 1);
Canvas->LineTo(BL + 1, BB - 1);
Canvas->Brush->Color = clBtnFace;
TX = BR + 5;
TY = (Hei

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号