ListboxControl 每行显示不同颜色 、字体、背景

ListboxControl 每行显示不同颜色 、字体、背景

1 设置 AllowHtmlDraw


listBoxControl1.AllowHtmlDraw = DevExpress.Utils.DefaultBoolean.True;
listBoxControl1.ItemAutoHeight = true;  // 设置item自动高度  (字体变大后item之间会重叠)

2 设置字体 颜色 背景


  listBoxControl1.Items.Add("<size=16><color=red>" +"测试"+ "</color><size>");

2.1 Color Backcolor Size Tags


 
<color> and <backcolor> Tags
Examples:
<color=red>Text</color>, <backcolor=red>Text</backcolor>
<color=0,255,0>Text</color>, <backcolor=0,255,0>Text</backcolor>
<color=255,0,255,0>Text</color> <backcolor=255,0,255,0>Text</backcolor>
<color=#0000FF>Text</color>” <backcolor=#0000FF>Text</backcolor><size> Tag
Examples:
<size=10>10pt text</size>
<size=+4>Larger text</size>
<size=-4>Smaller text</size>

3 示例


listBoxControl1.AllowHtmlDraw = DevExpress.Utils.DefaultBoolean.True;
listBoxControl1.ItemAutoHeight = true;  // 设置item自动高度  (字体变大后item之间会重叠)


 private void ListMsg(string msg)
 {
         listBoxControl1.Items.Add("<size=16><color=" + GetColor(msg) + ">" + " " + msg + "</color><size>");
         //滚动到最后一行
         if (this.listBoxControl1.Items.Count > 0)
         {
             this.listBoxControl1.SelectedIndex = listBoxControl1.Items.Count - 1;
         }

         // 超出x行,倒序删除一部分
         if (listBoxControl1.Items.Count>20)
         {
             for (int i = 10; i >= 0; i--)
             {
                 listBoxControl1.Items.RemoveAt(i); 
             }
         }
 }


List<string> lsErrorMsg = new List<string>{"NG","失败" };
private string GetColor(string msg)
{
   string strColor = "Black";
    // 如果传入消息中 有NG,失败等字符则使用红色字体
   if (lsErrorMsg.Any(a => msg.Contains(a)))
   {
       strColor = "Red";
   }
   else
   {
       strColor = "Black";
   }
   return strColor;
}

效果图
在这里插入图片描述


参考官方文档
DevExpress ListboxControl 属性

DevExpress ListboxControl 方法

Color Backcolor Size Tags

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值