listbox1添加的字符根据条件改变颜色???在线等(100)

  • 主题发起人 hongshanwdj
  • 开始时间
H

hongshanwdj

Unregistered / Unconfirmed
GUEST, unregistred user!
while not adoTable3.Eof do begin if s<>adoTable3.FieldByName('编号').asstring then begin s:=adotable3.FieldByName('编号').asstring; s1:=adotable3.FieldByName('是否发送').asstring; if s1='是' then begin listbox1.Items.Add(s); 在这里添加代码使添加的s字体变为绿色 end else begin listbox1.Items.Add(s); 在这里添加代码使添加的s字体变为红色; end; end; adoTable3.Next; end;
 
S

szhcracker

Unregistered / Unconfirmed
GUEST, unregistred user!
可能要用发送消息地方法。
 
H

happycyp

Unregistered / Unconfirmed
GUEST, unregistred user!
参考下面这个:After dropping a TListBox on your form, you must change the Style property of the TListBox to lbOwnerDrawFixed. If you fail to change the Style property, the OnDrawItem event will never be called. Put the following code in the OnDrawItem event of your TListBox: ~~~~~~~~~~~~~~~~~~~~~~~~~procedure TForm1.ListBox1DrawItem (Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState) ;var myColor: TColor; myBrush: TBrush;begin myBrush := TBrush.Create; with (Control as TListBox).Canvas do begin if not Odd(Index) then myColor := clSilver else myColor := clYellow; myBrush.Style := bsSolid; myBrush.Color := myColor; Windows.FillRect(handle, Rect, myBrush.Handle) ; Brush.Style := bsClear; TextOut(Rect.Left, Rect.Top, (Control as TListBox).Items[Index]) ; MyBrush.Free; end;end;你的根据你的条件,设置(Control as TListBox).Canvas.Font.Color就可以了。
 
H

hongshanwdj

Unregistered / Unconfirmed
GUEST, unregistred user!
非常感谢,我是菜鸟,请问怎么设置?
 
H

hongshanwdj

Unregistered / Unconfirmed
GUEST, unregistred user!
谢谢大家了我用RichEdit了
 

Similar threads

S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
I
回复
0
查看
679
import
I
顶部