
Drac's questions on drop down lists in combo boxes
Drac, I tried to e-mail you but my server rejected your address, so I am
posting the answer to your question here...
<We have a dropdown usercontrol not written by me>
<but I am now responsable for maintaining it. The>
<problem I have is that it uses setcapture while>
<the dropdown part is shown. This causes a problem>
<when the list has enough items in it to cause the>
<scollbar to be shown.>
<>
<The mouseclick is captured by the listbox but has>
<no effect the scrollbar.>
<>
<I can't seem to get the hwnd of this scrollbar.>
<>
<How can I make it work so that if the user has>
<clicked on the scollbar then the scollbar moves?>
<>
<The only alternative I have at the moment it to>
<remove the setcapture, which as you know causes>
<the dropdown part to remain on screen under>
<certain circumstances.>
<>
< appreciate any enlightenment.>
You just asked the $60,000 question, or, in your case, the 60,000 Question.
The MouseMove event for the DropDown picturebox needs to ReleaseCapture from
the dropdown and SetCapture to the scrollbar when the mouse is over the
scroll bar.
This allows the mouse to interact with the scroll bar, letting the user drag
the thumbtrack or click on the slider bar or the buttons. If the scroll bar
supported a MouseMove event as well, we could use it to pass control back to
the DropDown when the mouse moves away from the scroll bar. However, the
scroll bar doesnt support any such event, so I had to code around it!
Now comes the tricky bit...
Include a timer in the user control. When the SetCapture is given to the
scroll bar, enable the timer with an interval of 10 (1/100th of a second).
Each time the timer goes off (Timer1_Timer event), get the current position
of the mouse cursor on the screen (GetCursorPos API). If the mouse cursor is
no longer over the scroll bar, SetCapture back to the DropDown picture box
and disable the timer!
You can get the RECT of the scroll bar and DropDown picture box using the
GetWindowRect API, passing the handle (.hwnd property) of the scroll bar and
picture box. If, for some reason, you are not getting the hwnd property of
the scroll bar supported, call Microsoft! Just kidding. The hwnd property
has been supported on all controls since VB 4.
Hope this helps! Martin.