我在Form上放了一个TListBox,把它的Style属性设为lbOwnerDrawVariable.
在Items加了7项内容。在MeasureItem加了Height := 30;这一句,但是,这句
却不起作用。通过设断点,也根本执行不到这一句。
各位大虾,这是否就是Delphi的一个Bug.请指正。
另:我Delphi6是打了补丁2了的。
在Items加了7项内容。在MeasureItem加了Height := 30;这一句,但是,这句
却不起作用。通过设断点,也根本执行不到这一句。
各位大虾,这是否就是Delphi的一个Bug.请指正。
另:我Delphi6是打了补丁2了的。
Rect: TRect; State: TOwnerDrawState); 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 thenbegin
BrushCopy(Bounds(Rect.Left + Offset, 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;procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
begin
if Index mod 2 = 0 then
Height := 30
else
Height := 10;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.Items.Add('aaaa');
ListBox1.Items.Add('bbbb');
ListBox1.Items.Add('cccc');
ListBox1.Items.Add('dddd');
ListBox1.Items.Add('eeee');
ListBox1.Items.Add('ffff');
ListBox1.Items.Add('gggg');
end;
ListBox1.Style := lbOwnerDrawVariable.
to sundayboysII(空):Delphi 7下我没试过,我的是Delphi 6
to tonylk(=www.tonixsoft.com=):事件是绝对关联起来了的。(在Form的DFM文件里已包含这两句OnDrawItem = ListBox1DrawItem
OnMeasureItem = ListBox1MeasureItem)
谢谢楼上两位的热心参与。各位大虾如有不同见解,请回复。
7天内结贴。
to fxjpost(天外有天):你试过了没有?