VB .NET • Override the OnDropDown Show Method

Listing 1. Overriding the OnDropDownShow method is approximately equivalent to handling the DropDownShow event and lets you alter the appearance of the drop down menu before it appears. To get the Office 2003 expandable menu behavior, you need to make selected items invisible and start a timer.

	ByVal e As System.EventArgs)
	If Not Me.DesignMode Then
		If Not inExpandedClick Then
			Dim hasExpandable As Boolean = False
			Dim itemCount As Int32 = 0
			For Each item As ToolStripItem In _
			Dim toolstripMenuItem As ToolStripMenuItem = _
				TryCast(item, ToolStripMenuItem)
		If toolstripMenuItem IsNot Nothing Then
			itemCount += 1
			Dim menuItem As SpecialMenuItem = _
				TryCast(item, SpecialMenuItem)
		If menuItem IsNot Nothing Then
			If Not menuItem.IsDisplayed _
				And Not menuItem.AlwaysHidden Then
					hasExpandable = True
					menuItem.Visible = False
					itemCount -= 1
			End If
		End If
		End If

		If itemCount < mMinimumItemCount Then
			hasExpandable = Not DisplayMinimumItems()
		End If
		If hasExpandable Then
		End If
		End If
	End If
	End Sub

Protected Overrides Sub OnDropDownOpened( _
	ByVal e As System.EventArgs)
	Me.timer.Enabled = True
End Sub