• <tfoot id='T4Zt3'></tfoot>

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

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

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

        <legend id='T4Zt3'><style id='T4Zt3'><dir id='T4Zt3'><q id='T4Zt3'></q></dir></style></legend>
      1. Windows.Forms.ListBox 与 OwnerDrawVariable 错误?

        时间:2023-10-07

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

                    <tbody id='NX62B'></tbody>
                • <small id='NX62B'></small><noframes id='NX62B'>

                  本文介绍了Windows.Forms.ListBox 与 OwnerDrawVariable 错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在属性 DrawMode 设置为 OwnerDrawVariableWindows.Forms.ListBox 中,ListBox 似乎缓存物品的高度,有什么好处.

                  In a Windows.Forms.ListBox with the property DrawMode set to OwnerDrawVariable, the ListBox seems to cache the height of the items, what is good.

                  BUT,是依赖于宽度的item高度,因为它使用Graphics.MeasureString来做自动换行,如果ListBox已更改.那么问题来了.

                  BUT, being the item height dependent of the width, because it uses Graphics.MeasureString to do word wrap, needs to calculate the height of items if the size of the ListBox has changed. Then there's a problem.

                  ListBox默认不这样做,我找不到清除缓存的方法,强制ListBox引发itemheight事件.

                  The ListBox doesn't do this by default, and I can't find a method to clear the cache, forcing the ListBox to raise the itemheight event.

                  有什么解决办法吗?我试图获取 ListBox 的源代码,但没有找到任何相关信息来创建派生类并清除此缓存.

                  Any solution? I tried to get the source for the ListBox but don't find anything about that to make a derived class and clear this cache.

                  (尝试将项目复制到数组中,清除 ListBox.Items,然后再次添加数组.这甚至会在 ListBox 调用 drawitem 或项目索引无效的项目高度事件)

                  (Tried copying the items to an array, clearing the ListBox.Items, and tem adding the array again. This even throw exceptions as the ListBox calling the drawitem or itemheight events with invalid item index)

                  推荐答案

                  根据这个 MSDN

                  LB_SETITEMHEIGHT 消息

                  设置列表框中项目的高度(以像素为单位).如果列表框有LBS_OWNERDRAWVARIABLE 样式,此消息设置项目的高度由 wParam 参数指定.否则,此消息设置高度列表框中的所有项目.

                  Sets the height, in pixels, of items in a list box. If the list box has the LBS_OWNERDRAWVARIABLE style, this message sets the height of the item specified by the wParam parameter. Otherwise, this message sets the height of all items in the list box.

                  这样就可以了

                  private const int LB_SETITEMHEIGHT = 0x01A0;
                  
                  [DllImport("user32.dll")]
                  public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
                  
                  private void ListBoxExample_Resize(object sender, EventArgs e)
                  {
                      for (int i = 0; i < ListBoxExample.Items.Count; i++)
                      {
                  
                          MeasureItemEventArgs eArgs = new MeasureItemEventArgs(null, i);
                          ListBoxExample_MeasureItem((object)ListBoxExample, eArgs);
                          SendMessage((IntPtr) ListBoxExample.Handle, LB_SETITEMHEIGHT, (IntPtr) i, (IntPtr) e.ItemHeight);
                      }
                  }
                  

                  MeasureItemEventArgs 接受 Graphics 对象,如有必要,从控件创建一个对象并将其传递到第一个参数中.

                  The MeasureItemEventArgs accepts a Graphics object, if necessary, create one from the control and pass it in the first argument.

                  这篇关于Windows.Forms.ListBox 与 OwnerDrawVariable 错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  1. <tfoot id='7LpGV'></tfoot>
                      <tbody id='7LpGV'></tbody>
                    1. <small id='7LpGV'></small><noframes id='7LpGV'>

                        <bdo id='7LpGV'></bdo><ul id='7LpGV'></ul>
                        • <legend id='7LpGV'><style id='7LpGV'><dir id='7LpGV'><q id='7LpGV'></q></dir></style></legend>