Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting info on dropdown arrrow in a combo box ?

Status
Not open for further replies.

lizray

Programmer
May 14, 2008
126
AU
I have a combo box and want to generate an event on mousedown when the mouse is over the drop down arrow. Does any one know how can I get the dimensions of the drop down arrow ?
 
Dimensions? You mean the coordinates of the mouse cursor?

Code:
Private Sub MyComboBox_MouseDown(Button As Integer, Shift As Integer, [highlight]X As Single, Y As Single[/highlight])
    
End Sub

I believe the X and Y coordinates are your current mouse icon coordinates... X and Y like on a graph.. showing the screen location.

I could be remembering incorrectly, but I'm pretty sure that's it.

If you're talking about something else, please give more detail.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
I think the X and Y refer to the mouse coords (in twips). I wanted to know when the mouse was over the dropdown arrow on the right side. I notice that the cursor actually changes to an arrow and the dropdown actually becomes darker and wondered if there is a way of detecting these conditions.
 
Well, there is the "On Hover" command as well that will tell you that...

So whenever "On MouseMove" is activated, that's when the control acts the way you describe. So you'd want to capture the coordinates at that time. Well, you'd want to capture MousMove when your new control has the focus, and the Detail area of the form does not have focus, probably.

I don't remeember what/where it is off-hand, but I remember downloading a database from an MS Access MVP (I think it was an MVP) that had a setup that would show you every detail of every action when you ran their database. So it was interesting in that it showed what events trigger when, as well as things like where your mouse cursor is located.

But if you just need to do something once the item is hovered over, then you need the "MouseMove" event... and if you're wanting to act while hovering over that item, then you'll need to test to see whether it has focus or not.. if if does, act, if not, don't act. It may sound simpler than it is - I forget, but I know I've done it in the past.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
If you really need to know when the mouse is over the dropdown arrow, you can try something like:
Add a couple unbound text boxes to your form (or a test form):
txtX
txtY
Then add code to the MouseMove event of the combo box (assumes combo box name is "cboMyComboBox")
Code:
Private Sub cboMyComboBox_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Me.txtX = X
    Me.txtY = Y
[green]    'assumes the width of the arrow is 255 twips[/green]
    If Me.cboMyComboBox.Width - X < 255 Then
        Me.txtX.ForeColor = vbRed
     Else
        Me.txtX.ForeColor = vbBlack
    End If
End Sub
The txtX color should change colors when the mouse is over the arrow.


Duane
Hook'D on Access
MS Access MVP
 
Thanks Duane, I had been trying to detect the mouse over the Arrow by using the screen.mousepointer, but it keeps returning a value of zero, so your silution seems to work eell
 
I spent a fair few hours searching for a satisfactory answer to this question.
My particular requirements were that I wanted a ComboBox to only be re queried when the user started to change something, rather than using the GotFocus event, which occurs through ordinary navigation
This could be achieved by the KeyDown Event along with a pseudo 'DropDown' Event.
Although the X,Y coords from the Mouse Events are useful for the 'DropDown' Event, it requires a 'guess' on how wide the ComboBox Down Arrow is.

In the end, this is what I came up with - inspiration from Stephen Lebans.

Code:
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTL) As Long
Private Declare Function apiGetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassname As String, ByVal nMaxCount As Long) As Long
Private Const ACC_CBX_EDIT_CLASS = "OKttbx" '  class name for Edit controls in Access
Private Type POINTL
    X As Long
    Y As Long
End Type

Private WithEvents mCB As Access.ComboBox

Public Sub SetControl(ByVal oComboBox As Access.ComboBox)
    Set mCB = oComboBox
    mCB.OnMouseDown = "[Event Procedure]" 'Enable combobox events
End Sub

Private Sub mCB_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

    'ComboBox has the Focus

    If fCBDownArrowClicked Then

        'ComboBox Down Arrow has been clicked
        
    End If
End Sub

Private Function fCBDownArrowClicked() As Boolean
Dim lRet As Long
Dim hwnd As Long
Dim pt As POINTL

    'Find current Cursor position
    lRet = GetCursorPos(pt)
    
    'Get this point's Window
    hwnd = WindowFromPoint(pt.X, pt.Y)
    
    'Class Name is 'oFormChild' if CB down arrow was clicked in a single or continuous form
    '           or 'oGrid"      if CB down arrow was clicked in a datasheet form
    '           or 'OKttbx'     if CB Edit Box (to the left of the down arrow) was clicked
    If fGetClassName(hwnd) <> ACC_CBX_EDIT_CLASS Then cbDownArrowClicked = True

End Function

Private Function fGetClassName(hwnd As Long)
Dim strBuffer As String
Dim lngLen As Long
Const MAX_LEN = 255
    strBuffer = Space$(MAX_LEN)
    lngLen = apiGetClassName(hwnd, strBuffer, MAX_LEN)
    If lngLen > 0 Then fGetClassName = Left$(strBuffer, lngLen)
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top