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

    <small id='5S09U'></small><noframes id='5S09U'>

    <tfoot id='5S09U'></tfoot>

    1. <legend id='5S09U'><style id='5S09U'><dir id='5S09U'><q id='5S09U'></q></dir></style></legend>

      Listbox 手动 DrawItem 大字号

      Listbox manual DrawItem big font size(Listbox 手动 DrawItem 大字号)

      • <tfoot id='1qTWo'></tfoot>
          1. <legend id='1qTWo'><style id='1qTWo'><dir id='1qTWo'><q id='1qTWo'></q></dir></style></legend>

              <tbody id='1qTWo'></tbody>

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

                <small id='1qTWo'></small><noframes id='1qTWo'>

                本文介绍了Listbox 手动 DrawItem 大字号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试以红色绘制以 * 字符结尾的项目(并删除该 * 字符)并以黑色绘制其他项目.

                I'm trying to draw items that end of them is an * character in red (and remove that * character) and draw other items in black color.

                这是我的代码:

                    private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
                    {
                        e.DrawBackground() ; //Draw our regular background
                        if (Microsoft.VisualBasic.Strings.Right(listBox1.Items[e.Index].ToString(), 1) == "*")
                        {
                            e.Graphics.DrawString(Microsoft.VisualBasic.Strings.Mid(listBox1.Items[e.Index].ToString(),1,listBox1.Items[e.Index].ToString().Length - 1), e.Font, Brushes.Red, e.Bounds);    //Draw the item text in red!
                        }
                        else
                        {
                            e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font, Brushes.Black, e.Bounds); //Draw the item text in its regular color
                        }
                    }
                

                还将列表框的 DrawMode 属性设置为 OwnerDrawVariable.

                Also DrawMode property of the listbox is set to OwnerDrawVariable.

                当列表框的字体为默认字体时,我的代码工作正常.

                My code is working fine when the font of listbox is the default font.

                但是当我将字体大小从 8.25(默认大小)更改为 14 时,一半的文本绘制在列表框上.像这样:

                But When I change the font size from 8.25 (default size) to 14, half of the text draws on the listbox. like this:

                但是使用默认字体大小,一切都是正确的.

                But with default font size, everything is correct.

                有什么问题?

                推荐答案

                你必须处理 MeasureItem 事件并在那里设置项目的高度:

                You have to handle the MeasureItem event and set the height of the items there:

                private void listBox1_MeasureItem(object sender, MeasureItemEventArgs e)
                {
                     e.ItemHeight = listBox1.Font.Height;
                }
                

                这篇关于Listbox 手动 DrawItem 大字号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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 列表框上的取消选择)

                    <tfoot id='U1M6e'></tfoot><legend id='U1M6e'><style id='U1M6e'><dir id='U1M6e'><q id='U1M6e'></q></dir></style></legend>
                      <bdo id='U1M6e'></bdo><ul id='U1M6e'></ul>
                    • <small id='U1M6e'></small><noframes id='U1M6e'>

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

                            <tbody id='U1M6e'></tbody>