Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting the clicked object on a context menu
Message
De
24/08/2005 23:04:45
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Menus
Titre:
Getting the clicked object on a context menu
Versions des environnements
Environment:
VB.NET 1.1
OS:
Windows XP
Divers
Thread ID:
01043684
Message ID:
01043684
Vues:
56
Hi everyone. I'm new to VB.net and I'm trying so hard to get this simple code to work.
My problem lies at the event handler of the menuitem. The messagebox at the event handler
correctly displays the selected menuitem's text from the contextmenu, but the second messagebox in the Button1_Click sub routine doesn't display it correctly.

But if I uncomment the MsgBox("delay") statement the code works well.
What am I doing wrong.

Any help will be very much appreciated
--------------------------------------------------------------------------------------------
Public Class Form1
	Inherits System.Windows.Forms.Form


	Private selected As String = ""
	Private cm As New ContextMenu

#Region " Windows Form Designer generated code "
#End Region

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		cm.MenuItems.Add("Text1", AddressOf mnuHandler)
		cm.MenuItems.Add("Text2", AddressOf mnuHandler)
		cm.MenuItems.Add("Text3", AddressOf mnuHandler)
		cm.MenuItems.Add("Text4", AddressOf mnuHandler)
	End Sub

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

		selected = "INIT"

		cm.Show(TextBox1, New Point(0, 0))

		'IF THE LINE BELOW IS UNCOMMENTED, THE CODE WORKS
		'MsgBox("delay")

		'must display the clicked menuitem's text
		MsgBox(selected)
	End Sub

	Private Sub mnuHandler(ByVal sender As Object, ByVal e As System.EventArgs)
		selected = CType(sender, MenuItem).Text

		'this displays the correct selected menuitem's text
		MsgBox(selected + " inside")
	End Sub
End Class
--------------------------------------------------------------------------------------------
OMAR C. IBRAHIM
----------
Programmer
STUDENT RECORDS & INFORMATION SYSTEM (SRIS)
Western Mindanao State University, Philippines
----------
Programmer
SSI Engineering & Architectural Designs and IT Center (SENARD ITC)
Zamboanga City, Philippines
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform