我在Form上放了一个TListBox,把它的Style属性设为lbOwnerDrawVariable.
在Items加了7项内容。在MeasureItem加了Height := 30;这一句,但是,这句
却不起作用。通过设断点,也根本执行不到这一句。
各位大虾,这是否就是Delphi的一个Bug.请指正。
另:我Delphi6是打了补丁2了的。

解决方案 »

  1.   

    我用delphi7,测试代码如下,没有问题。procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
      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;
      

  2.   

    问题解决。在设计期把Style属性设为lbStandard,然后在Form的Create事件里加上
    ListBox1.Style := lbOwnerDrawVariable.
    to sundayboysII(空):Delphi 7下我没试过,我的是Delphi 6
    to tonylk(=www.tonixsoft.com=):事件是绝对关联起来了的。(在Form的DFM文件里已包含这两句OnDrawItem = ListBox1DrawItem
        OnMeasureItem = ListBox1MeasureItem)
    谢谢楼上两位的热心参与。各位大虾如有不同见解,请回复。
    7天内结贴。
      

  3.   

    這個不是bug,是你的程序哪裡不對
      

  4.   

    我在Form上放了一个TListBox,把它的Style属性设为lbOwnerDrawVariable.直接设置ItemHeight就可以改变高度呀。
      

  5.   

    to  konhon(优华无限):要是我的ItemHeight是变化的呢?比如说根据图片的高度来改变。
    to fxjpost(天外有天):你试过了没有?