相关疑难解决方法(0)

ListBox项的背景颜色(winforms)

如何在System.Windows.Forms.ListBox中设置特定项的背景颜色?如果可能的话,我希望能够设置多个.

c# listbox colors winforms

48
推荐指数
2
解决办法
9万
查看次数

如何在C#WinForms中为Listbox/ListView行的部分着色?

  1. 有没有办法为ListBox项目的部分(不仅是整行)着色?例如,列表框项目由5个单词组成,只有一个是彩色的,或者是5个中的3个.
  2. 有没有办法对ListView做同样的事情?(我知道ListView可以按列着色,但我希望在一列中有多种颜色).

我只对免费的解决方案感兴趣,并且希望它们不会很难实现或改变当前的使用情况(引入彩色ListBox代替普通的更好的努力).

带着敬意,

疯狂的男孩

c# listview listbox colors winforms

8
推荐指数
1
解决办法
5687
查看次数

按C#中的代码设置列表框项的字体和颜色

我正忙于一个自定义列表框,我在c#中用作注册阅读器.现在,我想在一个确定的项目中设置一个确定的项目,其中的字体和颜色与其他项目不同.我检查了这个问题,并从答案中我做了以下代码:

private void myListBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
    e.DrawBackground();
    Font myFont;
    Brush myBrush;
    int i = e.Index;

    if (e.Index == 3)
    {
        myFont = e.Font;
        myBrush = Brushes.Black;
    }
    else
    {
        myFont = new Font("Microsoft Sans Serif", 9.75f, FontStyle.Bold);
        myBrush = Brushes.CadetBlue;
    }

    e.Graphics.DrawString(myListBox.Items[i].ToString(), myFont, myBrush, e.Bounds, StringFormat.GenericDefault);
}
Run Code Online (Sandbox Code Playgroud)

并使用我的IntializeComponent()调用该方法

this.myListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.myListBox_DrawItem);
Run Code Online (Sandbox Code Playgroud)

该调用不会抛出任何异常,但我看到我想要处理的行没有变化.有什么我想念的吗?

c# listbox winforms

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×3

listbox ×3

winforms ×3

colors ×2

listview ×1