TButton 버턴에 멀티라인이 표시되었으면 할때가 가끔 있는데
그런 간단한 동작을 위해 컴포넌트를 새로 설치하기도 그렇고
새로 버턴을 만들기도 그렇고, 간단히 속성을 바꾸는 코드를 모든 버턴에
적용하려니 조금 귀잖기도 하고,
이럴때 가장 간편하게 문제를 해결하는 방법은 이겁니다.
물론 빌더2007은 WordWrap 속성이 있으니 이게 전혀 필요없지만 빌더6는 가끔 필요할 때도 있을 겁니다.
그런데 똑 같은 방법을 TBitBtn에 적용하면 전혀 먹지 않습니다.
이건 너무 당연한 현상으로, TButton과는 달리 TBitBtn은 버턴 모양을 OS에 맡기지 않고 직접 그리기
때문입니다. 그러므로 TBitBtn의 캡션을 멀티라인으로 표시하고 싶으면 직접 그려주는 방법을
써야 합니다.
윈도 메시지 핸들러를 아래처럼 만들어서
MESSAGE void __fastcall CNDrawItem(Messages::TWMDrawItem &Message);
처리해주면됩니다.
자세한 방법은 VCL의 Buttons.pas 소스 안을 보시면 확실히 아실 수 있습니다.
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
//---------------------------------------------------------------------------
// 멀티라인 캡션 표시 TButton.
class TButton : public Stdctrls::TButton
{
typedef Stdctrls::TButton inherited;
protected:
virtual void __fastcall CreateParams(Controls::TCreateParams &Params)
{
inherited::CreateParams(Params);
Params.Style |= BS_MULTILINE;
}
};
#define TButton ::TButton
//---------------------------------------------------------------------------
class TForm4 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
TButton *Button2;
void __fastcall FormCreate(TObject *Sender);
void __fastcall Memo1Change(TObject *Sender);
void __fastcall SpeedButton1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm4(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm4 *Form4;
//---------------------------------------------------------------------------
#endif
이런거 신경쓰기 싫으면 빌더2007로 가시면 됩니다.
-,.-; 잠이 안와서 아주 간단한거 하나 올렸습니다.
그럼
|
SetWindowLong(Button1->Handle,GWL_STYLE, GetWindowLong(Button1->Handle,GWL_STYLE) | BS_MULTILINE);