TCustomControl 在 TWinControl 的基础上只添加了一个 Canvas 属性 和 一个 Paint 方法,和你的要求完全一样。
可以通过继承 TCustomControl 定义控件,省去了很多的麻烦。
//---------------------------------------------------------------------------
class PACKAGE TMyWinControl : public TCustomControl
{
private:
TNotifyEvent FUserPaint;
protected:
virtual void __fastcall Paint(void);
public:
__property Canvas;
__fastcall TMyWinControl(TComponent* Owner);
__published:
__property TNotifyEvent OnPaint = { read = FUserPaint, write = FUserPaint };
};
//---------------------------------------------------------------------------
__fastcall TMyWinControl::TMyWinControl(TComponent* Owner)
: TCustomControl(Owner)
{
FUserPaint = NULL;
}
//---------------------------------------------------------------------------
void __fastcall TMyWinControl::Paint(void)
{
TCustomControl::Paint();
if(FUserPaint)FUserPaint(this);
}
//---------------------------------------------------------------------------
--------------------next---------------------
阅读(1198) | 评论(0) | 转发(0) |