|
TImage와 TSpeedButton이 같은 크기, 같은 위치에 놓이도록 컴포넌트로 만들려고 합니다.
TSpeedButton을 상속받은 새로운 클래스안에서 TImage를 멤버로 하는 컴포넌트를 만들었는데,
Object Inspector 에서 수치를 입력하면 같이 변경은 됩니다만,
폼 디자인에서 새로만든 버튼을을 움직여도 TImage 컨트롤이 화면상에서 같이 안움직이네요.
폼 디자인에서 같이 움직이게 하려면 어떻게 해야하죠??
///////////////////////////////////////////////////////////////////////////////
// .h
class PACKAGE TMyImageButton : public TSpeedButton
{
private:
TImage* FImage;
void __fastcall SetLeft(int left);
void __fastcall SetTop(int left);
void __fastcall SetWidth(int width);
void __fastcall SetHeight(int height);
protected:
public:
__fastcall TMyImageButton(TComponent* Owner);
__published:
__property TImage* Image={ read=FImage };
__property int Left={ read=FLeft, write=SetLeft };
__property int Top={ read=FTop, write=SetTop};
__property int Width={ read=FWidth, write=SetWidth };
__property int Height={ read=FWidth, write=SetWidth };
};
//---------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
// .cpp
__fastcall TMyImageButton::TMyImageButton(TComponent* Owner)
: TSpeedButton(Owner)
{
FImage=new TImage(Owner);
FImage->Parent=dynamic_cast<TWinControl*>(Owner);
FImage->Left=TSpeedButton::Left;
FImage->Top=TSpeedButton::Top;
FImage->Width=TSpeedButton::Width;
FImage->Height=TSpeedButton::Height;
}
//---------------------------------------------------------------------------
void __fastcall TMyImageButton::SetLeft(int left)
{
TSpeedButton::Left=left;
FImage->Left=left;
}
//---------------------------------------------------------------------------
void __fastcall TMyImageButton::SetTop(int top)
{
TSpeedButton::Top=top;
FImage->Top=top;
}
//---------------------------------------------------------------------------
void __fastcall TMyImageButton::SetWidth(int width)
{
TSpeedButton::Width=width;
FImage->Width=width;
}
//---------------------------------------------------------------------------
void __fastcall TMyImageButton::SetHeight(int height)
{
TSpeedButton::Height=height;
FImage->Height=height;
}
//---------------------------------------------------------------------------
|