【问题标题】:Set the dropdownheight for a combobox c# CF3.5为组合框 c# CF3.5 设置下拉高度
【发布时间】:2023-03-30 02:50:01
【问题描述】:

有没有办法在 CF3.5 中设置组合框的下拉高度? CF 中没有这样的属性,我似乎也无法在设计中做到这一点。任何帮助表示赞赏,谢谢。

//--------------------------------------------- - - - - - - - - 更新 - - - - - - - - - - - - - - - - - ------------------------------------//

    [DllImport("coredll.dll")]
    private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

    [StructLayout(LayoutKind.Sequential)]
    struct RECT
    {
        public int left, top, right, bottom;
    }

    [StructLayout(LayoutKind.Sequential)]
    struct COMBOBOXINFO
    {
        public int cbSize;
        public RECT rcItem;
        public RECT rcButton;
        public int stateButton;
        public IntPtr hwndCombo;
        public IntPtr hwndItem;
        public IntPtr hwndList;
    }

    public static IntPtr IntPtrAlloc<T>(T param)
    {
        IntPtr retval = Marshal.AllocHGlobal(Marshal.SizeOf(param));
        Marshal.StructureToPtr(param, retval, false);
        return retval;
    }

    COMBOBOXINFO cbi = new COMBOBOXINFO();
    IntPtr cbiPointer = IntPtrAlloc(cbi);
    SendMessage(comboBox1.Handle, CB_GETCOMBOBOXINFO, IntPtr.Zero, cbi);

【问题讨论】:

    标签: c# compact-framework windows-ce


    【解决方案1】:

    我自己没有尝试过,但我相信可以做到。 覆盖组合框的 OnHandleCreated,使用 pinvoke 调用带有 CB_GETCOMBOBOXINFO (0x0162) 的 SendMessage,这将返回一个包含下拉列表控件句柄的 Comboboxinfo 结构,将句柄存储到下拉列表中。当您想使用下拉列表和所需高度的句柄更新下拉高度时,请 pinvoke SetWindowPos。

    【讨论】:

    • 嗨,我上次没有跟进这个帖子,因为我找到了另一种方法来解决这个问题。现在,我想测试您的建议,但我似乎无法找到一种方法来传递 SendMessage 中的组合框结构以填充信息。我添加了一些示例 sn-p,希望您能纠正我,谢谢。
    猜你喜欢
    • 1970-01-01
    • 2011-02-02
    • 2012-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-08
    • 1970-01-01
    相关资源
    最近更新 更多