DropDown control implementation like ComboBox without stealing focus from form?

DropDown control implementation like ComboBox without stealing focus from form?

Post by den Irma » Sat, 19 Nov 2005 02:17:46


Hello,

I'm createing a custom control from scratch and this control has a dropdown
portion just like combobox...

To have a professional look, I've to take care some points while the
dropdown is shown such as :

1) It should not steal focus from the Form.
2) It should be focusable.
3) It should catch all the mouse events while it's visible.

To achieve this I create the dropdown control and show it like this :

[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

[DllImport("user32")]
private static extern int SetParent(IntPtr hWndChild,IntPtr hWndNewParent);

[DllImport("user32")]
private static extern int SetCapture(int hwnd);

--- The code that shows the DropDown portion---

SetParent(MyListBox.Handle,IntPtr.Zero);
ShowWindow(MyListBox.Handle,4);
SetCapture(MyListBox.Handle.ToInt32());

As you can see, I'm setting the parent of the dropdown to desktop. Than
showing the window and setting the capture to that window.

The only succesfull part of the code is that the form does not loose the
focus. But I can't set the focus to the control and neither it captures the
mouse.

Can anybody point me what I'm doing wrong or know any way to achieve the
effect I want?

Regards,

den Irmak