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