Search code examples
.netwinformscontextmenustrip

ContextMenuStrip Custom Layout


I'm trying to have a Windows Forms ContextMenuStrip control display a list of countries, about 200 total. Currently it displays them all vertically which creates for a long wait time to scroll to countries near the bottom of the list. I've tried messing with the ContextMenuStrip.LayoutStyle property but it hasn't gotten me anywhere. Might anyone have any tips for this? I've also search google but haven't found the answer. Thanks for any help!


Solution

  • I don't know of a way to use a mouse roller or page down with a context menu. Instead of a contextMenuStrip you could open a form containing a docked listbox with the 200 countries in it, and return the selection via global or public variable. Formborderstyle = none will get rid of the title bar. You can use events other than doubleclick if you want it to more closely mimick the context menu user interface.

    Public Class Form1
      Public selectedCountry As String
      Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Right Then Form2.ShowDialog()
      End Sub
    End Class
    
    Public Class Form2
      Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        Form1.selectedCountry = ListBox1.SelectedItem
        Me.Close()
      End Sub
    End Class