Windows.Forms.ListBox with OwnerDrawVariable bug?

邮差的信 提交于 2019-12-01 01:21:40

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!