//for Delphi6.0 procedure TForm1.Button3Click(Sender: TObject); var Col: Integer; begin Col := 3; if Col >= RichEdit1.Lines.Count then Exit; RichEdit1.CaretPos := Point(0, Col); RichEdit1.SelLength := Length(RichEdit1.Lines[Col]); RichEdit1.SelAttributes.Color := clRed; end;
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); begin with TListBox(Control).Canvas do begin FillRect(Rect); if Index = 2 then Font.Color := clRed; TextOut(Rect.Left, Rect.Top, TListBox(Control).Items[Index]); end; end;procedure TForm1.FormCreate(Sender: TObject); begin ListBox1.Style := lbOwnerDrawFixed; //直接到窗体里设置 end;
procedure TForm1.Button3Click(Sender: TObject);
var
Col: Integer;
begin
Col := 3;
if Col >= RichEdit1.Lines.Count then Exit;
RichEdit1.CaretPos := Point(0, Col);
RichEdit1.SelLength := Length(RichEdit1.Lines[Col]);
RichEdit1.SelAttributes.Color := clRed;
end;
如果LISTBOX 中的ITEM项,能设置为不同的颜色吗????????????
Rect: TRect; State: TOwnerDrawState);
begin
with TListBox(Control).Canvas do begin
FillRect(Rect);
if Index = 2 then Font.Color := clRed;
TextOut(Rect.Left, Rect.Top, TListBox(Control).Items[Index]);
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.Style := lbOwnerDrawFixed; //直接到窗体里设置
end;