<legend id='MQk7r'><style id='MQk7r'><dir id='MQk7r'><q id='MQk7r'></q></dir></style></legend>

      • <bdo id='MQk7r'></bdo><ul id='MQk7r'></ul>

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

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

      C# 我可以在列表框中显示图像吗?

      时间:2023-10-07
    2. <legend id='mqVQB'><style id='mqVQB'><dir id='mqVQB'><q id='mqVQB'></q></dir></style></legend>
        <tfoot id='mqVQB'></tfoot>

            <bdo id='mqVQB'></bdo><ul id='mqVQB'></ul>

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

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

                本文介绍了C# 我可以在列表框中显示图像吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                C# 简而言之,我可以在列表框中显示图像吗?我有一个用户列表,我想在某些名称旁边显示一个绿色勾号,这可能吗?

                C# In a nut shell can I display images in a list box? I have a list of users and I want to display a green tick next to some of the names, is this possible?

                谢谢

                推荐答案

                下面的代码展示了如何在列表框中进行自定义绘图.

                The following code displays how to do custom drawing in a listbox.

                using System.Windows.Forms;
                using System.Drawing;
                
                namespace Toolset.Controls
                {
                    public class CustomDrawListBox : ListBox
                    {
                        public CustomDrawListBox()
                        {
                            this.DrawMode = DrawMode.OwnerDrawVariable; // We're using custom drawing.
                            this.ItemHeight = 40; // Set the item height to 40.
                        }
                
                        protected override void OnDrawItem(DrawItemEventArgs e)
                        {
                            // Make sure we're not trying to draw something that isn't there.
                            if (e.Index >= this.Items.Count || e.Index <= -1)
                                return;
                
                            // Get the item object.
                            object item = this.Items[e.Index];
                            if (item == null)
                                return;
                
                            // Draw the background color depending on 
                            // if the item is selected or not.
                            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                            {
                                // The item is selected.
                                // We want a blue background color.
                                e.Graphics.FillRectangle(new SolidBrush(Color.Blue), e.Bounds);
                            }
                            else
                            {
                                // The item is NOT selected.
                                // We want a white background color.
                                e.Graphics.FillRectangle(new SolidBrush(Color.White), e.Bounds);
                            }
                
                            // Draw the item.
                            string text = item.ToString();
                            SizeF stringSize = e.Graphics.MeasureString(text, this.Font);
                            e.Graphics.DrawString(text, this.Font, new SolidBrush(Color.White),
                                new PointF(5, e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2));
                        }
                    }
                }
                

                这篇关于C# 我可以在列表框中显示图像吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在 WinForms 中将字典绑定到 ListBox 下一篇:C#:更改列表框行颜色?

                相关文章

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

                  <bdo id='uEdYN'></bdo><ul id='uEdYN'></ul>

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

                1. <tfoot id='uEdYN'></tfoot>