5 Years
Discussion Span
Last Post by Jollyyy100

Yes, it is possible.
Assuming your MDI Child is Form2:

Public Class Form2

	Private thisMenu As ContextMenu

	Private Sub Form2_Load(sender As Object, e As System.EventArgs) Handles Me.Load
		thisMenu = New ContextMenu
		Dim item1 As New MenuItem("entry1", AddressOf Item1_Click, Nothing)
		Dim item2 As New MenuItem("entry2", AddressOf Item2_Click, Nothing)
	End Sub

	Private Sub Form2_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
		If e.Button = MouseButtons.Right Then
			thisMenu.Show(Me, e.Location)
		End If
	End Sub

#Region "Context Item Handlers"

	Private Sub Item1_Click(ByVal sender As Object, ByVal e As EventArgs)
		MsgBox("You clicked 'entry1'")
	End Sub

	Private Sub Item2_Click(ByVal sender As Object, ByVal e As EventArgs)
		MsgBox("You clicked 'entry2'")
	End Sub

#End Region

End Class

Another thing you can do is just drag and drop a ContextMenuStrip onto the form from the designer. Then click on the form and set its ContextMenuStrip property to the menu you dropped on it. When you drop a menustrip it will show up in the component tray at the bottom of the designer. Click on it and you can edit the menu at design time.

That way you won't need to handle the forms mouse up event and won't have to deal with adding the items programmatically.


Thank you lots GeekByChoiCe and Unhnd Exception, it works now :D

Edited by Jollyyy100: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.