• <tfoot id='YApLU'></tfoot>
    <i id='YApLU'><tr id='YApLU'><dt id='YApLU'><q id='YApLU'><span id='YApLU'><b id='YApLU'><form id='YApLU'><ins id='YApLU'></ins><ul id='YApLU'></ul><sub id='YApLU'></sub></form><legend id='YApLU'></legend><bdo id='YApLU'><pre id='YApLU'><center id='YApLU'></center></pre></bdo></b><th id='YApLU'></th></span></q></dt></tr></i><div id='YApLU'><tfoot id='YApLU'></tfoot><dl id='YApLU'><fieldset id='YApLU'></fieldset></dl></div>

      1. <small id='YApLU'></small><noframes id='YApLU'>

      2. <legend id='YApLU'><style id='YApLU'><dir id='YApLU'><q id='YApLU'></q></dir></style></legend>
          <bdo id='YApLU'></bdo><ul id='YApLU'></ul>

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

        Way to color parts of the Listbox/ListView line in C# WinForms?(在 C# WinForms 中为 Listbox/ListView 行的部分着色的方法?)
      3. <tfoot id='endm6'></tfoot>
          <bdo id='endm6'></bdo><ul id='endm6'></ul>
        • <i id='endm6'><tr id='endm6'><dt id='endm6'><q id='endm6'><span id='endm6'><b id='endm6'><form id='endm6'><ins id='endm6'></ins><ul id='endm6'></ul><sub id='endm6'></sub></form><legend id='endm6'></legend><bdo id='endm6'><pre id='endm6'><center id='endm6'></center></pre></bdo></b><th id='endm6'></th></span></q></dt></tr></i><div id='endm6'><tfoot id='endm6'></tfoot><dl id='endm6'><fieldset id='endm6'></fieldset></dl></div>

                <tbody id='endm6'></tbody>
              <legend id='endm6'><style id='endm6'><dir id='endm6'><q id='endm6'></q></dir></style></legend>
                • <small id='endm6'></small><noframes id='endm6'>

                • 本文介绍了在 C# WinForms 中为 Listbox/ListView 行的部分着色的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

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

                  我只对免费的解决方案感兴趣,并且更喜欢它们不会繁重地实施或改变当前的使用(引入彩色 ListBox 来代替普通的最好的工作量最少).

                  I am interested in only free solutions, and preferred that they are not heavy to implement or change current usage (the least effort to introduce colored ListBox in place of normal one the better).

                  关于,

                  疯子

                  推荐答案

                  本文 讲述如何使用 DrawItem 的 ListBox 的 DrawMode 设置为 OwnerDraw 值之一.基本上,你可以这样做:

                  This article tells how to use DrawItem of a ListBox with DrawMode set to one of the OwnerDraw values. Basically, you do something like this:

                  listBox1.DrawMode = OwnerDrawFixed;
                  listBox1.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.listBox1_DrawItem);
                  
                  private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
                  {
                  e.DrawBackground();
                  e.DrawFocusRectangle();
                  // TODO: Split listBox1.Items[e.Index].ToString() and then draw each separately in a different color
                  e.Graphics.DrawString(listBox1.Items[e.Index].ToString(),new Font(FontFamily.GenericSansSerif, 14, FontStyle.Bold),new SolidBrush(color[e.Index]),e.Bounds);
                  }
                  

                  代替单个 DrawString 调用,将 listBox1.Items[e.Index].ToString() 拆分为单词并为每个单词单独调用 DrawString.您必须将 e.bounds 替换为 x,y 位置或每个单词的边界矩形.

                  Instead of the single DrawString call, Split listBox1.Items[e.Index].ToString() into words and make a separate call to DrawString for each word. You'll have to replace e.bounds with an x,y location or a bounding rectangle for each word.

                  同样的方法应该适用于 ListView.

                  The same approach should work for ListView.

                  这篇关于在 C# WinForms 中为 Listbox/ListView 行的部分着色的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                  listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                  Cannot remove items from ListBox(无法从列表框中删除项目)
                  Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                  Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                  Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)
                  • <bdo id='Yn5A3'></bdo><ul id='Yn5A3'></ul>

                      <small id='Yn5A3'></small><noframes id='Yn5A3'>

                        <tbody id='Yn5A3'></tbody>

                        <i id='Yn5A3'><tr id='Yn5A3'><dt id='Yn5A3'><q id='Yn5A3'><span id='Yn5A3'><b id='Yn5A3'><form id='Yn5A3'><ins id='Yn5A3'></ins><ul id='Yn5A3'></ul><sub id='Yn5A3'></sub></form><legend id='Yn5A3'></legend><bdo id='Yn5A3'><pre id='Yn5A3'><center id='Yn5A3'></center></pre></bdo></b><th id='Yn5A3'></th></span></q></dt></tr></i><div id='Yn5A3'><tfoot id='Yn5A3'></tfoot><dl id='Yn5A3'><fieldset id='Yn5A3'></fieldset></dl></div>
                            <legend id='Yn5A3'><style id='Yn5A3'><dir id='Yn5A3'><q id='Yn5A3'></q></dir></style></legend>

                            <tfoot id='Yn5A3'></tfoot>