|
이벤트가 발생되는 시점을 확인 안하셔서 발생된 오류라 판단되네요
OnPaint 이벤트는 객체 자신을 그리고 난후에 호출됩니다.
TForm을 모두 그리고 난후에 호출 된 이후 자식들을 그리기 시작합니다.
그럼으로 이미 그려진 이후에 다시 자식들이 그려지기 때문에 그려지지 않은것 처럼 보여지는것이지요
그려지지 않은것은 아닙니다.
김명구 님이 쓰신 글 :
: 빌더를 사용한지 얼마 안되는 초보자입니다.
:
: 프로그램을 실행하고 메뉴에서 해당 폼을 실행하면 폼에 있는 버튼들에 색을 입히는 프로그램을 만들고 있습니다.
: 폼이 호출되면 버튼에 색을 칠하는 루틴을 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();
: }
: //---------------------------------------------------------------------------
|