将ListBox的Style设为lbOwnerDrawFixed,然后再OnDrawItem事件中画。
解决方案 »
- 关于进度及进度条的问题
- 通过扫描图片得到的HRGN,创建不规则窗体,如何保存HRGN到文件,避免每次扫描
- 一个比较苦恼的问题(SQL操作Access)
- 急救:DELPHI xml 封装 !
- 升星,散分,今天是个值得纪念的日子
- 求哪里有delphi6或delphi7的CD2的下载!
- 急问:怎样把一个MEMO控件的内容的每一行作为报表打印出来?用QuikReport。
- 一个小问题
- 大家讨论一下自己最喜欢的第三方控件!!!
- 动态创建窗体的问题(急)
- 总出错,请问如何用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]一次!谢谢