Category / Section
How to prevent DropDownPopup from closing when mouse moves away in Ribbon control
2 mins read
This article explains how to customize the behavior of dropdown buttons in the Ribbon control, ensuring the dropdown remains open even when the mouse moves away.
By default, when using ToolStripDropDownButton in WinForms, the dropdown closes when the focus is lost (e.g., when the mouse moves away from the dropdown button). To address this behavior, we can implement custom logic in the Closing event of the dropdown. This ensures that the dropdown remains open until the user explicitly clicks on another dropdown button, rather than closing automatically on hover.
'
' Handle DropDownButton closing event
'
AddHandler ToolStripDropDownButton1.DropDown.Closing, AddressOf DropDown_Closing
AddHandler ToolStripDropDownButton2.DropDown.Closing, AddressOf DropDown_Closing
AddHandler ToolStripDropDownButton3.DropDown.Closing, AddressOf DropDown_Closing
Private Sub DropDown_Closing(sender As Object, e As ToolStripDropDownClosingEventArgs)
If e.CloseReason = ToolStripDropDownCloseReason.AppFocusChange Then
e.Cancel = True
End If
End Sub
Output: