为什么在listbox中隔行自画图象会出现不显示,单击选择后才显示图象?(50分)

  • 主题发起人 主题发起人 zouming
  • 开始时间 开始时间
Z

zouming

Unregistered / Unconfirmed
GUEST, unregistred user!
为什么在listbox中隔行自画图象会出现不显示,单击选择后才显示图象?代码如下:
procedure TTaxAndCostStandardForm.LB_MessageDrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
with LB_Message.Canvas do
begin
FillRect(Rect);
Font.Name := LB_Message.Items[Index];
Font.Size := 0; // use font's preferred size
TextOut(Rect.Left+Image1.ClientWidth+1, Rect.Top+1, LB_Message.Items[Index]);
case LB_Message.ItemIndex of
0,4:
Draw(Rect.Left+1, Rect.Top+1, Image1.Picture.Graphic);
end;
UpDate;
//TextOut(Rect.Left+1, Rect.Top+1, ListBox1.Items[Index]);
end;
end;

procedure TTaxAndCostStandardForm.LB_MessageMeasureItem(
Control: TWinControl; Index: Integer; var Height: Integer);
begin
with LB_Message.Canvas do
begin
Font.Name := LB_Message.Items[Index];
Font.Size := 0; // use font's preferred size
Height := TextHeight('Wg') + 2; // measure ascenders and descenders
Image1.Height := Height;
Image1.Width := Height;
end;
end;
 
我改了一下,运行正确了:
procedure TForm1.LB_MessageDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with LB_Message.Canvas do
begin
FillRect(Rect);
Font.Name := LB_Message.Items[Index];
Font.Size := 0; // use font's preferred size
TextOut(Rect.Left+Image1.ClientWidth+1, Rect.Top+1, LB_Message.Items[Index]);
case Index mod 2 of //用INDEX而不是ITEMINDEX
0:
Draw(Rect.Left+1, Rect.Top+1, Image1.Picture.Graphic);
end;
//UpDate;
//TextOut(Rect.Left+1, Rect.Top+1, ListBox1.Items[Index]);
end;

end;
 
如果隔5行,而不是2行,应如何改代码?
 
accept answer.
 
后退
顶部