[BCB] PageControl的標籤頁文字上色

PageControl的標籤頁文字上色
//首先 PageControl 的 OwnerDraw 要設成 true
void __fastcall Tform_settings::FormCreate(TObject *Sender)
{
 PageControl1->OwnerDraw = true;
}
//在PageControl 的 DrawTab Event 加入下列的code 
void __fastcall Tform_settings::PageControl1DrawTab(
TCustomTabControl *Control, int TabIndex, const TRect &Rect,
bool Active)
{  
  
    //PageControl Tab上色
    if(PageControl1->ActivePageIndex == TabIndex) {
        PageControl1->Canvas->Font->Color=clRed;
    }
    else {
        PageControl1->Canvas->Font->Color=clBlue;
    }
  
    PageControl1->Canvas->TextOut(Rect.Left,Rect.Top,PageControl1->Pages[TabIndex]->Caption);
}
不過BCB還是會有一點點的小Bug 在一開始的時候顏色會不太對,
點個幾下才會正常,目前還不知道要怎解...

留言

  1. 參考版主的程式將DrawTab事件改成下面這樣即可正常切換
    //------------------------------------------------------------//

    void __fastcall TForm1::PCDrawTab(TCustomTabControl *Control,
    int TabIndex, const TRect &Rect, bool Active)
    {
    TPageControl *pPageCtrl = dynamic_cast(Control);
    //PageControl Tab上色
    if(Active) {
    pPageCtrl->Canvas->Font->Color = clRed;
    }
    else {
    pPageCtrl->Canvas->Font->Color = clBlue;
    }

    pPageCtrl->Canvas->TextOut(Rect.Left,Rect.Top," "+pPageCtrl->Pages[TabIndex]->Caption);

    }
    //---------------------------------------------------------------------------

    回覆刪除

張貼留言