We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,657 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Right Click Option

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.

3
Contributors
3
Replies
1 Day
Discussion Span
1 Year Ago
Last Updated
5
Views
Question
Answered
Jollyyy100
Junior Poster in Training
93 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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)
		thisMenu.MenuItems.Add(item1)
		thisMenu.MenuItems.Add(item2)
	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
GeekByChoiCe
Master Poster
721 posts since Jun 2009
Reputation Points: 208
Solved Threads: 169
Skill Endorsements: 1

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.

Unhnd_Exception
Deleted Member

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

Jollyyy100
Junior Poster in Training
93 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by GeekByChoiCe and Unhnd_Exception

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0731 seconds using 2.64MB