ListBox的style |
尚未結案
|
noah_J
一般會員 發表:10 回覆:10 積分:4 註冊:2006-10-18 發送簡訊給我 |
請問各位大大:
我想把ListBox顯示的方式變的比較漂亮,也就是想要有個底圖,每個item的間距想要大一點,然後當滑鼠點下後,那個item的背景想要變一下顏色,且當按下上下鈕的時候,想讓整個Item有上下移的效果(假設有10筆資料,但只有顯示5筆資料,所以需要上下移動)。 我有試過將ListBox的style改成lbOwnerDrawFixed,然後去OnDrawItem畫,可是我試的結果是下一筆的資料會把上一筆的字給蓋住(我把ItemHeight的大小改成比較大),而且當滑鼠點到時,位置似乎不太對,請問有什麼比較好的方式可以達到我的要求嗎?或是有大大知道 OnData這幾個event該怎麼用呢?? 以下是我抄BCB OnDrawItem的程式 void __fastcall TForm1::ListBox1DrawItem(TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State) { Graphics::TBitmap *pBitmap; // temporary variable for item bitmap int Offset = 10; // default text offset width // note that we draw on the listbox canvas, not on the form TCanvas *pCanvas = ((TListBox *)Control)->Canvas; pCanvas->FillRect(Rect); // clear the rectangle pBitmap = (Graphics::TBitmap *)((TListBox *)Control)->Items->Objects[Index]; if (pBitmap) { pCanvas->BrushCopy(Bounds(Rect.Left Offset, Rect.Top Offset, pBitmap->Width, pBitmap->Height), pBitmap, Bounds(0, 0, pBitmap->Width, pBitmap->Height), clRed); // render bitmap Offset = pBitmap->Width 4; // add four pixels between bitmap and text } // display the text pCanvas->TextOut(Rect.Left Offset, Rect.Top Offset, ((TListBox *)Control)->Items->Strings[Index]); } |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |