当前位置导航:炫浪网>>网络学院>>编程开发>>C++教程>>C++基础入门教程

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

    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;
    }

 

共2页 首页 上一页 1 2 下一页 尾页 跳转到
相关内容
赞助商链接