如何在 ComboBox 加入BMP的圖檔作為 item? |
答題得分者是:RedSnow
|
capyu
一般會員 發表:17 回覆:23 積分:7 註冊:2005-01-23 發送簡訊給我 |
我是參考這一篇寫的 http://delphi.ktop.com.tw/topic.php?topic_id=60598 TForm1 *Form1;
TComboBox *ComboBox1;
TImage *Image1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
ComboBox1=new TComboBox(this);
ComboBox1->OnDrawItem=ComboBox1DrawItem;--> 這一行都會出錯
ComboBox1->Style=csOwnerDrawFixed;
ComboBox1->Parent=Form1;
ComboBox1->Items->Add("");
ComboBox1->Items->Add("");
ComboBox1->Items->Add("");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ComboBox1DrawItem(TWinControl *Control,
int Index,
TRect &Rect,
TOwnerDrawState State)
{
Image1=new TImage(this);
Image1->Picture->LoadFromFile(IntToStr(Index 1) ".bmp");
// 自己畫選項
ComboBox1->Canvas->StretchDraw(Rect, Image1->Picture->Bitmap);
ComboBox1->Canvas->FrameRect(Rect);
} // 以下是 header ================== class TForm1 : public TForm
{
__published: // IDE-managed Components
void __fastcall ComboBox1DrawItem(TWinControl *Control,
int Index,
TRect &Rect,
TOwnerDrawState State);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
}; 錯誤訊息:
[C Error] Unit1.cpp(18): E2034 Cannot convert 'void (_fastcall * (_closure )(TWinControl *,int,TRect &,TOwnerDrawState))(TWinControl *,int,TRect &,TOwnerDrawState)' to 'void (_fastcall * (_closure )(TWinControl *,int,const TRect &,TOwnerDrawState))(TWinControl *,int,const TRect &,TOwnerDrawState)' 發表人 - capyu 於 2005/05/08 19:45:44 發表人 - capyu 於 2005/05/08 19:48:43
|
richtop
資深會員 發表:122 回覆:646 積分:468 註冊:2003-06-10 發送簡訊給我 |
capyu 您好: 如果您不是動態產生ComboBox1的話,那麼下列有兩行程式碼似乎可以刪去!
__fastcall TForm1::TForm1(TComponent* Owner) :TForm(Owner) {RichTop 敬上 =====***** 把數學當工具,可以解決問題;將數學變能力,能夠發現並解決問題! =====##### |
RedSnow
版主 發表:79 回覆:1322 積分:845 註冊:2003-12-15 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |