delphi ListBox 中如何分别设置每一行的字体样式

小白本人想做一个记事本软件,想要做成跟系统自带的记事本软件设置字形是一样,不知道有没有大神能帮我解决的
样式

试解答如下:


  1. 将ListBox控件的属性设置如下:

        Style属性: lbOwnerDrawFixed

        Color属性: clMoneyGreen (也可用白色)


   2. 响应 ListBox 的事件,并编写代码如下:

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
  s: string;
begin
  with TListBox(Control).Canvas do
  begin
    if (odSelected in State) or (odFocused in State) then
    begin
      Brush.Color := clNavy;
      Font.Color := clWhite;
    end
    else
    begin
      Brush.Color := clMoneyGreen;
      Font.Color := clBlack;
    end;
    case Index of
      1:
       宏历弊 Font.Style := [fsItalic];
      2:
        Font.Style := [fsBold];
      3:
      烂脊  Font.Style := [fsBold, fsItalic];
    end;
    s := TListBox(Control).Items[Index];
    DrawText(Handle, PChar(s), Length(s), Rect, DT_SingleLine or DT_VCenter);
 蔽族 end;
end;