Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all,

 

Trying to make a combobox get focus when you left click on another combobox while the list part is down of the other combobox. It takes two clicks now to give another combobox focus. I was thinking I could make the control have focus

where the cursor location is when I Left Mouse Down?

When you left mouse down or when the list part retracts

from the combo that you are on I could then catch

CBN_CLOSEUP, but doesn't seam to send the message all the time?

 

I have done alot of searching and find people telling to look at MSDN, but haven't found that to be very helpful or any samples to see how to use this in VB.NET.

 

Can someone please help

 

Public Class MyComboBox

Inherits System.Windows.Forms.ComboBox

 

Private Const CBN_DROPDOWN = 7

Private Const CBN_CLOSEUP = 8

Private Const WM_COMMAND As Long = &H111

Private Const WM_LBUTTONDOWN As Integer = &H201 '513

 

Public First As Boolean = False

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

 

 

If m.Msg = CBN_CLOSEUP Then

Console.Write(m.Msg & " ComboBox Retracting List" & vbCrLf)

 

'Maybe do something here to give control focus where

'the cursor is located.

 

End If

 

MyBase.WndProc(m)

 

 

End Sub

 

End Class

 

Thanks

Gerry

  • Leaders
Posted

why not do something like this :

   Private Sub ComboBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ComboBox1.MouseDown
       If ComboBox1.SelectedIndex <> -1 Then
           If e.Button = MouseButtons.Left Then
               ComboBox2.Focus()
           End If
       End If
   End Sub

   Private Sub ComboBox2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ComboBox2.MouseUp
       If ComboBox1.SelectedIndex <> -1 Then
       '/// add any code here to retrieve the combo item from ComboBox1.    
       ComboBox1.SelectedIndex = -1
       End If
   End Sub

Posted

Thanks for your help, but that

doesn't work.

 

While combobox1 list is being displayed and

you mouse over and click combobox2. Combobox2 doesn't get focus until you click again.

 

Any other help would be great.

 

Thanks

Gerry

  • 7 months later...
Posted
Try using form.GetChildtAtPoint(CursorPoint as point) at that should return the control you want. Then set the use that control to call focus to itself.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...