Why ComboBox hides cursor when DroppedDown is set?

后端 未结 5 1996
长发绾君心
长发绾君心 2020-12-07 00:23

Let\'s create WinForms Application (I have Visual Studio 2008 running on Windows Vista, but it seems that described situation takes place almost everywhere from Win98 to Vis

5条回答
  •  盖世英雄少女心
    2020-12-07 00:53

    In fact I was able to resolve this issue in this way:

    #region Dirty methods :)
    #pragma warning disable 169
    [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
    public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
    
    private const int MOUSEEVENTF_ABSOLUTE = 0x8000;
    private const int MOUSEEVENTF_MOVE = 0x1;
    private const int MOUSEEVENTF_LEFTDOWN = 0x02;
    private const int MOUSEEVENTF_LEFTUP = 0x04;
    private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
    private const int MOUSEEVENTF_RIGHTUP = 0x10;
    #pragma warning restore 169
    #endregion
    
    private void button1_Click(object sender, EventArgs e) {
       Point oldCursorPos = Cursor.Position; // save pos
       Point a = comboBox1.Parent.PointToScreen(comboBox1.Location);
       a.X += comboBox1.Width - 3;
       a.Y += comboBox1.Height - 3;
       Cursor.Position = a;
       // simuate click on drop down button
       mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
       Cursor.Position = oldCursorPos; // restore pos
    }
    

    But it is not the solution I want :( It is rather a crutch but not a solution.

提交回复
热议问题