Windows.Forms.ListBox with OwnerDrawVariable bug?

后端 未结 1 1490
感动是毒
感动是毒 2021-01-07 11:34

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

相关标签:
1条回答
  • 2021-01-07 11:47

    According this MSDN

    LB_SETITEMHEIGHT message

    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.

    So this will do it

    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);
        }
    }
    

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

    0 讨论(0)
提交回复
热议问题