|
빌더를 사용한지 얼마 안되는 초보자입니다.
프로그램을 실행하고 메뉴에서 해당 폼을 실행하면 폼에 있는 버튼들에 색을 입히는 프로그램을 만들고 있습니다.
폼이 호출되면 버튼에 색을 칠하는 루틴을 FormPaint에 코딩해주고 실행시켰는데 버튼색이 주어진 색으로 안바뀌고 그대로네요 무슨 문제가 있는 것인지......
관련된 소스를 올립니다.
========================================================
void __fastcall TfrmWatch::u_BtnStyle(TButton* Button, AnsiString* Title, TColor color)
{
tagSIZE btnTag;
int txtWidth, txtHeight;
TCanvas *btncan = new TCanvas();
btncan->Handle = GetDC(Button->Handle);
btncan->Brush->Style = bsSolid;
btncan->Brush->Color = color;
btncan->Pen->Color = clWhite;
btncan->Font->Color = clWhite;
btncan->Font->Size = -btncan->Font->Height * 100 / btncan->Font->PixelsPerInch;
btncan->Rectangle(Button->ClientRect);
txtWidth = btncan->TextWidth(Title[1]);
txtHeight = btncan->TextHeight(Title[1]);
btncan->TextOutA(Button->Width/2 - txtWidth/2,
Button->Height/2 - txtHeight/2, Title[1]);
ReleaseDC(Button->Handle, btncan->Handle);
delete btncan;
}
//---------------------------------------------------------------------------
void __fastcall TfrmWatch::u_SetBtn()
{
for( int i=0 ; i < this->ControlCount ; i++ )
{
if(this->Controls[i]->ClassNameIs("TGroupBox"))
{
TGroupBox * GBox = dynamic_cast<TGroupBox *>(this->Controls[i]);
for( int j=0 ; j < GBox->ControlCount ; j++)
{
if(GBox->Controls[j]->ClassNameIs("TButton"))
{
u_BtnStyle(dynamic_cast<TButton *>(GBox->Controls[j]),BTNTITLE, UNTRIP);
}
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmWatch::FormPaint(TObject *Sender)
{
u_SetBtn();
}
//---------------------------------------------------------------------------
|