📄 mycomponent.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "MyComponent.h"
#include "EditGraphic.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(TMyComponent *)
{
new TMyComponent(NULL);
}
//---------------------------------------------------------------------------
__fastcall TMyComponent::TMyComponent(TComponent* Owner)
: TWinControl(Owner)
{
BevelKind=bkSoft;
BevelInner=bvLowered;
BevelOuter=bvRaised;
BevelWidth=1;
Count=5;
Height=100;
Width=120;
FGraphics=new TMyGraphic;
IsMouseEnter=false;
}
//---------------------------------------------------------------------------
__fastcall TMyComponent::~TMyComponent()
{
delete FGraphics;
}
//---------------------------------------------------------------------------
int __fastcall TMyComponent::GetCount()
{
return FCount;
}
//---------------------------------------------------------------------------
void __fastcall TMyComponent::SetCount(int ACount)
{
if(FCount!=ACount)
{
FCount=ACount;
if(FCountChanged!=NULL)
FCountChanged(this,ACount);
}
}
//---------------------------------------------------------------------------
namespace Mycomponent
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TMyComponent)};
RegisterComponents("Samples", classes, 0);
RegisterPropertyEditor(__typeinfo(TMyGraphic),__classid(TMyComponent),
"Graphics",__classid(TMyPropertyEditor));
RegisterComponentEditor(classes[0],__classid(TMyComponentEditor));
}
}
//---------------------------------------------------------------------------
void __fastcall TMyPropertyEditor::SetValue(String Value)
{
((TMyComponent * )GetComponent(0))->Graphics->Test=StrToInt(Value);
}
//---------------------------------------------------------------------------
String __fastcall TMyPropertyEditor::GetValue()
{
String tmpS=IntToStr(((TMyComponent * )GetComponent(0))->Graphics->Test);
return tmpS;
}
//---------------------------------------------------------------------------
__fastcall TMyPropertyEditor::TMyPropertyEditor(const _di_IFormDesigner ADesigner, int APropCount):TPropertyEditor(ADesigner,APropCount)
{
}
//---------------------------------------------------------------------------
__fastcall TMyPropertyEditor::~TMyPropertyEditor()
{
//TODO: Add your source code here
}
//---------------------------------------------------------------------------
TPropertyAttributes __fastcall TMyPropertyEditor::GetAttributes()
{
return TPropertyAttributes()<<paDialog;
}
//---------------------------------------------------------------------------
void __fastcall TMyPropertyEditor::Edit()
{
frmEditGraphic=new TfrmEditGraphic(NULL);
frmEditGraphic->edTest->Text=IntToStr(((TMyComponent * )GetComponent(0))->Graphics->Test);
if(frmEditGraphic->ShowModal()==mrOk)
{
((TMyComponent * )GetComponent(0))->Graphics->Test=StrToInt(frmEditGraphic->edTest->Text);
}
delete frmEditGraphic;
}
//---------------------------------------------------------------------------
int __fastcall TMyComponent::GetPointArray(int Index)
{
if(Index>=0&&Index<5)
return FPointArray[Index];
else
return -1;
}
//---------------------------------------------------------------------------
void __fastcall TMyComponent::SetPointArray(int Index, int Value)
{
if(Index>=0&&Index<5)
FPointArray[Index]=Value;
}
//---------------------------------------------------------------------------
int __fastcall TMyComponentEditor::GetVerbCount()
{
return 2;
}
//---------------------------------------------------------------------------
String __fastcall TMyComponentEditor::GetVerb(int Index)
{
switch(Index)
{
case 0:
return "&About...";
case 1:
return "&Edit...";
}
return "unknow";
}
//---------------------------------------------------------------------------
void __fastcall TMyComponentEditor::ExecuteVerb(int Index)
{
switch(Index)
{
case 0:
Application->MessageBoxA("Produced by GanZhi","Hello",MB_OK);
break;
case 1:
String tmpS=IntToStr(((TMyComponent *)Component)->Count);
Application->MessageBoxA(("The Count Value is "+tmpS).c_str(),"Hello",MB_OK);
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TMyComponentEditor::Edit()
{
Application->MessageBoxA("\"Edit\" method is called","Edit...",MB_OK);
}
//---------------------------------------------------------------------------
void __fastcall TMyComponent::DoPaint(TWMPaint & Mess)
{
PAINTSTRUCT tmpPS;
HDC myhdc=BeginPaint(Handle,&tmpPS);
Ellipse(myhdc,0,0,ClientWidth,ClientHeight);
if(IsMouseEnter)
Ellipse(myhdc,1,1,ClientWidth-1,ClientHeight-1);
EndPaint(Handle,&tmpPS);
}
//---------------------------------------------------------------------------
__fastcall TMyGraphic::TMyGraphic()
{
Test=1985;
}
//---------------------------------------------------------------------------
void __fastcall TMyComponent::OnMouseEnter(TMessage &Mess)
{
IsMouseEnter=true;
Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TMyComponent::OnMouseLeave(TMessage & Mess)
{
IsMouseEnter=false;
Repaint();
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -