TWinControl轉TListBox的問題(包含DELPHI轉BCB問題) |
答題得分者是:taishyang
|
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
最近在找BCB的demo程式(indy)
卻只有DELPHI的......(被放棄的CB......) 在試著轉c 碼的同時,遇到了一點問題… [code delphi] procedure TfrmMain.lbProcessesDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); begin with Control as TListBox do begin Canvas.Brush.Color := Color; Canvas.FillRect(Rect); Canvas.Font.Color := TColor(Items.Objects[Index]); // 1. Canvas.TextOut(Rect.Left 2, Rect.Top, Items[Index]); // 2. end; end; [/code] 上面註解 1、2兩點,不論我怎麼對TWinControl Control轉型,就是沒辦法編譯成功 請問這問題該如何解呢? 以下是我做的內容,過不了啊~~~~~@@ [code cpp] void __fastcall TfrmMain::lbProcessesDrawItem(TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State) { ((TListBox*)Control)->Canvas->Brush->Color = Color; ((TListBox*)Control)->Canvas->FillRect(Rect); ((TListBox*)Control)->Font->Color = ((TListBox*)Control)->Items->Object[Index].GetText(); //掛點 ((TListBox*)Control)->Canvas->TextOut(Rect.left 2, Rect.top, ((TListBox*)Control)->Items[Index]); //掛點 } [/code] 編輯記錄
GrandRURU 重新編輯於 2009-04-03 17:33:31, 註解 無‧
|
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
不曉得行不行
void __fastcall TfrmMain::lbProcessesDrawItem(TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State) { TListBox *lb = (TListBox*)Control; if (lb){ lb->Canvas->Brush->Color = Color; lb->Canvas->FillRect(Rect); lb->Font->Color = clBlack; //需要TColor 資料型態 lb->Canvas->TextOut(Rect.left 2, Rect.top, lb->Items->Strings[Index]); } } |
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
哦哦!
可以過了! 真是太感謝 taishyang 大大了! 再請教一下 第一行的地方:c 沒有類似像delphi的語法嗎?還是delphi語法解釋出來就是這行?? (不知道 「Items.Objects[Index]」 怎麼解釋它) 第二行:如果改採 [code cpp] lb->Canvas->TextOut(Rect.left 2, Rect.top, lb->Items[Index].GetText()); [/code] 會同等第二句的語法嗎? ===================引 用 taishyang 文 章=================== [code cpp] lb->Font->Color = clBlack; //需要TColor 資料型態 lb->Canvas->TextOut(Rect.left 2, Rect.top, lb->Items->Strings[Index]); [/code] |
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |