N
niit
Unregistered / Unconfirmed
GUEST, unregistred user!
主要是画了之后有背景线,不知道是什么原因,如果不指定颜色的话就没有问题。不知道是什么原因,希望大家帮帮忙!这就是下面的代码
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
vStr: string;
vR: Integer;
begin
vR := SetBkMode(self.ListBox1.Canvas.Handle, TRANSPARENT);
if odSelected in State then
begin
ListBox1.Canvas.Brush.Color := clBlack;
ListBox1.Canvas.Pen.Color := clWhite;
end
else
begin
ListBox1.Canvas.Brush.Color := clRed;
ListBox1.Canvas.Pen.Color := clWhite;
end;
vStr := ListBox1.Items[Index];
Rect.Left := Rect.Left + 2 ;
Rect.Top := Rect.Top + 1;
Rect.Right := Rect.Right - 2;
Rect.Bottom := Rect.Bottom - 1;
ListBox1.Canvas.FillRect(Rect);
Windows.DrawText(ListBox1.Canvas.Handle, PChar(vStr), Length(vStr), Rect, DT_SINGLELINE or DT_LEFT or DT_VCENTER);
SetBkMode(Self.ListBox1.Canvas.Handle, vR);
end;
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
vStr: string;
vR: Integer;
begin
vR := SetBkMode(self.ListBox1.Canvas.Handle, TRANSPARENT);
if odSelected in State then
begin
ListBox1.Canvas.Brush.Color := clBlack;
ListBox1.Canvas.Pen.Color := clWhite;
end
else
begin
ListBox1.Canvas.Brush.Color := clRed;
ListBox1.Canvas.Pen.Color := clWhite;
end;
vStr := ListBox1.Items[Index];
Rect.Left := Rect.Left + 2 ;
Rect.Top := Rect.Top + 1;
Rect.Right := Rect.Right - 2;
Rect.Bottom := Rect.Bottom - 1;
ListBox1.Canvas.FillRect(Rect);
Windows.DrawText(ListBox1.Canvas.Handle, PChar(vStr), Length(vStr), Rect, DT_SINGLELINE or DT_LEFT or DT_VCENTER);
SetBkMode(Self.ListBox1.Canvas.Handle, vR);
end;