(高分求助!UP有分)怎么可以让Listbox(或者其他的相同控件)输出彩色的文字! 在owner draw中用canvas进行填写 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我可是动态的添加String相应的字体也要彩色的,最好能给我点源代码 1.ListBox1.Style:=lbOwnerDrawFixed;2.procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);begin with ListBox1.Canvas do begin Font.Color:=clRed; textout(Rect.Left,rect.Top,Listbox1.Items[Index]); end;end; for FatBoy(白胖) 这样不行,我要的是每一次输出String时都可以改变颜色的 颜色有没有规律?比如说可以由items[i]的内容来区别 颜色有没有规律?比如说可以由items[i]的内容来区别 颜色有没有规律?比如说可以由items[i]的内容来区别 没有规律,是动态的,就是在添加String的时候就可以改变String的字体颜色 怎么说呢,比如Listbox1。item。add(‘警告!’);如果这样的话就只能输出这段消息,我现在想输出‘警告’的同时,还要把‘警告’输出为红色。Listbox1。item。add(‘成功!’);输出‘成功!’的同时,还要把‘成功!’的字体变为绿色,以此类推! 根据每行的文字内容设定font.color不行吗?如:if pos('警告',Listbox1.items[index])>0 then font.color:=clRed else Font.color:=clGreen;Textout(rect.left,rect.top,listbox1.items[index]); 1. 定义一个记录类型 Titm=record Strs: string; // 加入listbox 的string Colr: TColor; // 相应行的颜色 end;2. 声明数组itms= array of Titm;3. 每次向listbox加入string前先将内容及color 加入到itms 数组4. listbox根据itms数组更新 楼上的白胖方法可能,什么浪费资源嘛,一个 TColor 才 4字节但可以不要定义个数组用 Items.AddObject('asfd', TColor(xxx)) 就可以了 楼上的是不是那种每一次输入STRING都要自画一下,而且还要把每一条STRING的颜色存入记录类型,另外 comanche(太可怕)说的‘用 Items.AddObject('asfd', TColor(xxx)) 就可以了 ’我还要试试 //发挥点想象吧procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);begin TListBox(Sender).Canvas.FillRect(Rect); if TListBox(Sender).Items[Index] = Edit1.Text then TListBox(Sender).Canvas.Font.Color := clRed; TListBox(Sender).Canvas.TextOut(Rect.Left + 2, Rect.Top + 2, TListBox(Sender).Items[Index]);end; 我up&up,看看有没有分!!! listbox想做出彩来好像只能用画的方法了,不知高手们还有什么好方法? 偶的老天爷呀!api函数SetTextColor()不就可以吗! 使用listbox是不行的,它每次都会重绘。使用picture自己画或用第三方控件 小弟急求文件传输的源码!请各位高人指点! QQ登陆不了,很郁闷!什么原因啊?请大家赐教! 文件方面的问题 delphi中如何使用海康威视的SDK 高手赐教,怎样实现这样的控件拖放? 登录窗口与MDI窗口问题 怎么样实现在这样的一个数据库功能 现在客户需要做一个修改数据的功能,是不是在查询界面那里让用户修改视图,请问前辈门对客户修改数据是怎样做这摸块的 大虾!!我用了IActiveDesktop接口进行编程,为什么编译的时候,显示"类没有注册"呢??? C/S+MSSQLSERVER程式,如何得出各电脑用户的在线状态? ========关于网站过滤======= socketserver?
ListBox1.Style:=lbOwnerDrawFixed;
2.
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with ListBox1.Canvas do begin
Font.Color:=clRed;
textout(Rect.Left,rect.Top,Listbox1.Items[Index]);
end;
end;
这样不行,我要的是每一次输出String时都可以改变颜色的
如果这样的话就只能输出这段消息,我现在想输出‘警告’的同时,还要把‘警告’输出为红色。
Listbox1。item。add(‘成功!’);
输出‘成功!’的同时,还要把‘成功!’的字体变为绿色,以此类推!
如:
if pos('警告',Listbox1.items[index])>0 then font.color:=clRed else Font.color:=clGreen;
Textout(rect.left,rect.top,listbox1.items[index]);
Titm=record
Strs: string; // 加入listbox 的string
Colr: TColor; // 相应行的颜色
end;
2. 声明数组
itms= array of Titm;
3. 每次向listbox加入string前先将内容及color 加入到itms 数组
4. listbox根据itms数组更新
但可以不要定义个数组
用 Items.AddObject('asfd', TColor(xxx)) 就可以了
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
TListBox(Sender).Canvas.FillRect(Rect);
if TListBox(Sender).Items[Index] = Edit1.Text then
TListBox(Sender).Canvas.Font.Color := clRed;
TListBox(Sender).Canvas.TextOut(Rect.Left + 2, Rect.Top + 2, TListBox(Sender).Items[Index]);
end;