I have a custom control, that shows a panel (similar to a combobox dropdown, or toolbar menu list) when it has focus.
When the control loses focus, it raises an event to close the panel (make it invisible).
The problem I'm having is that the panel has options to edit the custom control. How do I override the lostfocus, so that when focus is switched to either the custom control OR any controls in the panel I can ignor the Raiseevent.
I'm currently doing this:
When I click on something inside the panel, the custom control raises the txtText.LostFocus which is fine, I presume the problem is that the focus has not yet been passed to a new control, so the Me.Controls.Control.Focused is not set to anything.
Any suggestions on how to keep the panel open?
Any help would be greatly appreciated.
Thanks.
When the control loses focus, it raises an event to close the panel (make it invisible).
The problem I'm having is that the panel has options to edit the custom control. How do I override the lostfocus, so that when focus is switched to either the custom control OR any controls in the panel I can ignor the Raiseevent.
I'm currently doing this:
VB.NET:
Custom control:
Public Event ConfirmSelection()
Private Sub txtText_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtText.LostFocus
RaiseEvent ConfirmSelection()
End Sub
The EventHandler for the panel:
Private Sub ConfirmSelection() Handles InputBox.ConfirmSelection
If Not (HaveFocus()) Then
Me.Visible = False
End If
End Sub
Private Function HaveFocus() As Boolean
Dim result As Boolean = False
For Each itm As Control In Me.Controls
If itm.Focused Then
result = True
Exit For
End If
Next
Return result
End Function
When I click on something inside the panel, the custom control raises the txtText.LostFocus which is fine, I presume the problem is that the focus has not yet been passed to a new control, so the Me.Controls.Control.Focused is not set to anything.
Any suggestions on how to keep the panel open?
Any help would be greatly appreciated.
Thanks.
Last edited: