Hi All,

I wanted to know if its possible to create a right click function in vb.net MDI form.

Example the way we right click on any program it gives us a list of options, is it possible to do it in vb.net and how?

Need help, thank you.

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.

This question has already been answered. Start a new discussion instead.