将ListBox的Style设为lbOwnerDrawFixed,然后再OnDrawItem事件中画。
解决方案 »
- delphi7如何解释以下的数据(不知道是不是json)
- cxGrid 怎么在无数据源绑定情况下 显示数据
- 下载器问题?
- 在Delphi不能用j:=(2^i)来表示2的i次方 (j为Integer类型),问如何表示???!!!!
- 请求帮助!!!!!!!!!!!!!!!!谢谢.
- 如何为动态创建的控件添加事件过程?
- dbedit问题
- 请各位朋友帮忙解决一个dll 调用问题,立即给分!
- 关于NMSMTP的问题,请指教!
- DLL安装的问题。
- 总出错,请问如何用delphi 动态地添加一个worksheet给一个Excel文件
- 请问如何才能让DBGrid控件中的某一列的单元格进入编辑状态?其它列的单元格保持只读状态?
代码没有效率,所以还需要优化一下。另,我的ImageList的Width是16。
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
a: TBitmap;
b, c: TRect;
begin
a := TBitmap.Create;
try
ImageList1.GetBitmap(Index, a);
b := classes.Rect(0, 0, 16, 16);
c := classes.Rect(0, Rect.Top, 16, Rect.Bottom);
ListBox1.Canvas.CopyRect(c, a.Canvas, b);
ListBox1.Canvas.TextOut(18, Rect.Top, ListBox1.Items[Index]);
finally
a.Free;
end;
end;
问题可能出在这里。你先别动态为IMGLIST赋值,选几个不一样的图标。看看行不行。
如果行GetIco可能有问题。
高手,快来吧。
不然的话图标是画不出来的
如果你方便的话,把你的测试代码发到我的信箱?
[email protected] 谢谢
var
Bitmap: TBitmap; { temporary variable for the item抯 bitmap }
Offset: Integer; { text offset width }
begin
with (Control as TListBox).Canvas do { draw on control canvas, not on the form }
begin
FillRect(Rect); { clear the rectangle }
Offset := 2; { provide default offset }
Bitmap := TBitmap((Control as TListBox).Items.Objects[Index]); { get the bitmap }if Bitmap <> nil then
begin
BrushCopy(Bounds(Rect.Left + 2, Rect.Top, Bitmap.Width, Bitmap.Height),
Bitmap, Bounds(0, 0, Bitmap.Width, Bitmap.Height), clRed); {render bitmap}
Offset := Bitmap.width + 6; { add four pixels between bitmap and text}
end;
TextOut(Rect.Left + Offset, Rect.Top, (Control as TListBox).Items[Index]) { display the text }
end;
end;
麻烦你再发到 [email protected]一次!谢谢