viatorg Posted July 15, 2003 Posted July 15, 2003 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 Quote
Leaders dynamic_sysop Posted July 15, 2003 Leaders Posted July 15, 2003 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 Quote
viatorg Posted July 15, 2003 Author Posted July 15, 2003 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 Quote
viatorg Posted July 15, 2003 Author Posted July 15, 2003 Sorry for the wording above I mean where the Mouse Location is not Cursor!!!!!! thanks Gerry Quote
test Posted February 17, 2004 Posted February 17, 2004 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.