如何检查是否组合框下拉列表中显示向上或向下? [英] How to check if combobox drop down list is revealed up or down?

查看:393
本文介绍了如何检查是否组合框下拉列表中显示向上或向下?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有控制(实现C#.NET 2.0),它继承自组合框。它有过滤和其他的东西。为了保持用户界面右侧,当项目的筛选过程中跌倒量,下拉列表中改变其大小,以适应左项目金额(它是由NativeMethods.SetWindowPos(做...))。

I have control (implemented C#, .Net 2.0) that inherits from combobox. It has filtering and other stuff. To keep UI right, when amount of items during filtering falls, drop down list changes its size to fit the amount of items left (it is done by NativeMethods.SetWindowPos(...)).

有没有什么办法来检查,如果下拉列表中显示向上或向下(直译) - 不检查,如果它是开放的,它是开放的,但以何种方式,向上或向下

Is there any way to check if drop down list is revealed up or down (literally) - not to check if it is open, it is open, but in which way, up or down?

欢呼声,JBK

推荐答案

所以,我找到了答案:

在这里,我们有两个手柄,以组合框​​:

Here we have both handles to combobox:

    /// <summary>
    /// Gets a handle to the combobox
    /// </summary>
    private IntPtr HwndCombo
    {
        get
        {
            COMBOBOXINFO pcbi = new COMBOBOXINFO();
            pcbi.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(pcbi);
            NativeMethods.GetComboBoxInfo(this.Handle, ref pcbi);
            return pcbi.hwndCombo;
        }
    }

和以DROPDOWNLIST组合框的:

And to dropdownlist of combobox:

    /// <summary>
    /// Gets a handle to the combo's drop-down list
    /// </summary>
    private IntPtr HwndDropDown
    {
        get
        {
            COMBOBOXINFO pcbi = new COMBOBOXINFO();
            pcbi.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(pcbi);
            NativeMethods.GetComboBoxInfo(this.Handle, ref pcbi);
            return pcbi.hwndList;
        }
    }

现在,我们可以从手柄得到矩形:

Now, we can get rectangles from handles:

    RECT comboBoxRectangle;
    NativeMethods.GetWindowRect((IntPtr)this.HwndCombo, out comboBoxRectangle);

    // get coordinates of combo's drop down list
    RECT dropDownListRectangle;
    NativeMethods.GetWindowRect((IntPtr)this.HwndDropDown, out dropDownListRectangle);

现在我们可以检查:

    if (comboBoxRectangle.Top > dropDownListRectangle.Top)
    {
         ....
    }

这篇关于如何检查是否组合框下拉列表中显示向上或向下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆