屬性表標簽(tab control)支持在每一個item上放Image 圖片。在mfc下實現相當簡單,可分為以下幾步:
step1: create a bitmap resource with the images
you can also use icons or even create the images at run time.
the size of the images should be in proportion to the height
of the label.
step2: add member variable of type Cimagelist
protected:
CImagelist m_imagetab;
step3: Override OnInitDialog() and add code to it
bool CmyPropSheet::OnInitDialog()
{
bool bresult=CProperttySheet::OnInitDialog();
m_imagetab.create(IDB_TABIMAGES,13,1,RGB(255,255,255));
CTabCtrl *pTab=GetTabControl();
pTab->SetImageList(&m_imagetab);
tc_item tcitem;
tcitem.mask=tcif_image;
for(int i=0;i<3;i++)
{
tcitem.iimage=i;
pTab->SetItem(i,&tcitem);
}
return bresult;
}
C++Builder 沒有提供 SetImageList,SetItem這樣的函數,但我們可以直接處理WINDOWS API 消息:TCM_SETIMAGELIST,TCM_SETITEM. 看下面的代碼可以體會不同的編程風格。
void __fastcall TForm1::FormPaint(TObject *Sender)
{
TabControl1->Perform ( TCM_SETIMAGELIST, 0, ImageList1->Handle );
TCITEM tcitem;
tcitem.mask=TCIF_IMAGE ;
for(int i=0;i<3;i++)
{
tcitem.iImage=i;
TabControl1->Perform ( TCM_SETITEM, i,(LPARAM) (LPTCITEM) &tcitem );
}
}