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
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.
It's a strange set of circumstances where the combo box is a DropDownList
type and you call the DroppedDown
method on the combo box from within the code either while it has the focus or not.
The cursor will disappear as though behind the form. If you click the form the cursor comes back but the combo box closes so not a good result.
I can confirm that this code fixes the issue without closing the combo box list.
cbo_VisitorTypes.DroppedDown = true;
Cursor.Current = Cursors.Default;
For a start, it's a very obscure set of circumstances that I can't imagine being a useful interface action.
It would seem to be a bug that causes the programmatic dropdown to start editing in the text box that forms part of the dropdown control so effectively double hiding the cursor. To break it down...
I'd suspect that each hide stores the state of the cursor and restores it on exit.
The text box has stored the actual cursor state and hidden it.
The dropdown causes the hidden state to be stored and the cursor set to hidden. When you move the cursor it probably does restore it but to the hidden state it saved so the cursor remains hidden.
A click on the form seems to force a reset of that situation, not sure why on that but that's my 2 penneth worth.
I was able to work around the problem like this:
comboBox1.DroppedDown = true;
Cursor.Current = Cursors.Default;
I got this issue on a Delphi application. As suggested here I just added SendMessage(ComboBox1.Handle, WM_SETCURSOR, 0, 0)
after any DropDown event and it worked.