派生的Panle

HPP

#ifndef TpanelcheckH
#define TpanelcheckH
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Controls.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TPanelAddcheck :public TPanel
{
    private:
    bool bSelected;
    TWndMethod OldPanelProc;
    __published:	// IDE-managed Components
    TCheckBox *chkCheck;
    protected:
    public:
    void __fastcall NewPanelProc(Messages::TMessage &Message);
   // WindowProc(Messages::TMessage &Message);
   // virtual TMouseProperty __fastcall MousePosClass(int x, int y);   //判断该坐标是否在图元件中的边界位置
  // typedef void __fastcall (__closure *TWndMethod)(Messages::TMessage &Message);
    __fastcall TPanelAddcheck(TComponent* Owner);

};
#endif
CPP


#pragma hdrstop

#include "Tpanelcheck.h"

//---------------------------------------------------------------------------
__fastcall TPanelAddcheck::TPanelAddcheck(TComponent* Owner):TPanel(Owner)
{
  //  Top = top;
  //  Left = left;
  //  Height = height;
  //  Width = width;
  //  Cursor = crHandPoint;
     OldPanelProc = this->WindowProc; //保存旧窗口函数
     this->WindowProc = NewPanelProc; //设置新窗口函数
     chkCheck=new TCheckBox(Owner);
     chkCheck->Parent=this;
     chkCheck->Top=0;
     chkCheck->Left=0;
     chkCheck->Width=10;
     chkCheck->Height=10;
}
//---------------------------------------------------------------------------
void __fastcall TPanelAddcheck::NewPanelProc(Messages::TMessage &Message)
{

    static   TColor cl = clBlue;      //
    OldPanelProc(Message);   //执行默认动作
    switch (Message.Msg)
    {
         case WM_PAINT:
         {
             TRect rc = this->ClientRect;
             TControlCanvas *cvs = new TControlCanvas;
             cvs->Control = this;

             cvs->Font->Color = cl;
             cvs->Brush->Color = cl;
             cvs->Pen->Color=cl;


             cvs->Pen->Width   =   1;
            // cvs->Pen->Style= psDot    ;
            // cvs->FrameRect(rc);  //画边框
             cvs->Brush->Style = bsClear;;
             cvs->Rectangle(rc);
             //画文字
             DrawText(cvs->Handle, this->Caption.c_str(),
                 this->Caption.Length(),
                 &rc,
                 DT_SINGLELINE|DT_CENTER|DT_VCENTER);
             delete cvs;
         }
         break;
         case WM_LBUTTONDOWN:
             cl = clGreen;   //鼠标按下时Panel颜色
             this->Invalidate();
         break;
         case WM_LBUTTONUP:
             cl = clRed;  //鼠标未按下时Panel颜色
             this->Invalidate();
         break;
         case CM_MOUSELEAVE:
             cl = clYellow;  //鼠标未按下时Panel颜色
             this->Invalidate();
         break;
         case CM_MOUSEENTER:
             cl = clBlue;  //鼠标未按下时Panel颜色
             this->Invalidate();
         break;
         default:
         break;
    }

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值