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

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

  2. <legend id='Zp6sb'><style id='Zp6sb'><dir id='Zp6sb'><q id='Zp6sb'></q></dir></style></legend>

      • <bdo id='Zp6sb'></bdo><ul id='Zp6sb'></ul>
    1. <small id='Zp6sb'></small><noframes id='Zp6sb'>

      ListBox DrawItem HotLight 在 OwnerDraw 模式下的状态?

      ListBox DrawItem HotLight State in the OwnerDraw mode?(ListBox DrawItem HotLight 在 OwnerDraw 模式下的状态?)
    2. <small id='txmOL'></small><noframes id='txmOL'>

        <tbody id='txmOL'></tbody>

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

              • 本文介绍了ListBox DrawItem HotLight 在 OwnerDraw 模式下的状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在我的 WinForms 应用程序中使用 OwnerDrawFixed 作为自定义 ListBox 控件的 DrawMode.

                I'm using OwnerDrawFixed as a DrawMode for the custom ListBox control in my WinForms app.

                当用户将鼠标悬停在列表框项目上时,我想重新绘制 ListBoxItem 的背景(或执行一些其他操作),即在 MouseMove...

                I want to repaint the background (or do some other action) of the ListBoxItem when the user hovers over the listbox item, that is, at the MouseMove...

                DrawItemState.HotLight 从不适用于 ListBox,所以我想知道如何模拟它,如何解决这个问题.

                DrawItemState.HotLight never works for the ListBox, so i wonder how to emulate it, how to workaround this problem.

                推荐答案

                我只用了两年的时间才为你找到答案,但这里是:

                It took me only two years to find the answer for you, but here it is:

                DrawItemState.HotLight 仅适用于所有者绘制的菜单,而不适用于列表框.对于 ListBox,您必须自己跟踪项目:

                The DrawItemState.HotLight only applies to owner drawn menus, not the listbox. For the ListBox, you have to keep track of the item yourself:

                public partial class Form1 : Form
                {
                  private int _MouseIndex = -1;
                
                  public Form1()
                  { InitializeComponent(); }
                
                  private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
                  {
                    Brush textBrush = SystemBrushes.WindowText;
                
                    if (e.Index > -1)
                    {
                      if (e.Index == _MouseIndex)
                      {
                        e.Graphics.FillRectangle(SystemBrushes.HotTrack, e.Bounds);
                        textBrush = SystemBrushes.HighlightText;
                      }
                      else
                      {
                        if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                        {
                          e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds);
                          textBrush = SystemBrushes.HighlightText;
                        }
                        else
                          e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds);
                      }
                      e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font, textBrush, e.Bounds.Left + 2, e.Bounds.Top);
                    }
                  }
                
                  private void listBox1_MouseMove(object sender, MouseEventArgs e)
                  {
                    int index = listBox1.IndexFromPoint(e.Location);
                    if (index != _MouseIndex)
                    {
                      _MouseIndex = index;
                      listBox1.Invalidate();
                    }
                  }
                
                  private void listBox1_MouseLeave(object sender, EventArgs e)
                  {
                    if (_MouseIndex > -1)
                    {
                      _MouseIndex = -1;
                      listBox1.Invalidate();
                    }
                  }
                }
                

                这篇关于ListBox DrawItem HotLight 在 OwnerDraw 模式下的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                How to store delegates in a List(如何将代表存储在列表中)
                How delegates work (in the background)?(代表如何工作(在后台)?)
                C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)

                  <tbody id='NKKde'></tbody>

                    <tfoot id='NKKde'></tfoot>
                      <bdo id='NKKde'></bdo><ul id='NKKde'></ul>

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

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