DoyongID 님이 쓰신 글 : : TImage컴포넌트를 보면 Picture속성에 "..." 버튼이 있어서, 그걸 누르면 이미지를 고를 수 있습니다.. : : 제가 하려는건 오브젝트 인스펙터창에서 "..."을 누르면 TOpenPictureDialog창이 뜨면서 BMP를 선택하여 파일의 경로를 얻는 기능입니다.. : : 컴포넌트 제작시 오브젝트 인스펙터창에 "..." 버튼을 나타나게 하려고 하는데, 어떻게 해야하는건지 답변 부탁드립니다..
아래와 같이 만들면 TButton 을 상속하여 Picture 속성을 추가한 TmdButton 을 만들게 됩니다.
Picture 속성을 클릭하여 이미지를 불러오면 mdButton 에는 이미지의 Height 가 표시됩니다.
헤더 파일 mdButton.h 의 내용.
#ifndef mdButtonH #define mdButtonH //--------------------------------------------------------------------------- #include <SysUtils.hpp> #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> #include <Graphics.hpp> //--------------------------------------------------------------------------- class PACKAGE TmdButton : public TButton { private: TPicture *FPicture; //Image 를 담을 FPicture 의 포인터 void __fastcall SetPicture(TPicture *Picture); protected: public: __fastcall TmdButton(TComponent* Owner); virtual __fastcall ~TmdButton(); //파괴자 __published: __property TPicture* Picture={read=FPicture , write=SetPicture}; //Picture 속성 설정 }; //--------------------------------------------------------------------------- #endif
mdbutton.cpp 의 내용
//--------------------------------------------------------------------------- #include <vcl.h>
#pragma hdrstop
#include "mdButton.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(TmdButton *) { new TmdButton(NULL); } //--------------------------------------------------------------------------- __fastcall TmdButton::TmdButton(TComponent* Owner) : TButton(Owner) { FPicture = new TPicture(); //FPicture 객체 생성 }
__fastcall TmdButton::~TmdButton() { delete FPicture; //만든 객체 파괴 }
void __fastcall TmdButton::SetPicture(TPicture *Picture) { FPicture->Assign(Picture); //FPicture 에 Picture Editor 에서 불러온 Image 를 할당한다. this->Caption = FPicture->Height; //mdButton 의 Caption 에 불러온 이미지의 Height 표시 }
//--------------------------------------------------------------------------- namespace Mdbutton { void __fastcall PACKAGE Register() { TComponentClass classes[1] = {__classid(TmdButton)}; RegisterComponents("Samples", classes, 0); } } //---------------------------------------------------------------------------
|