Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting the clicked object on a context menu
Message
De
25/08/2005 01:23:12
 
 
À
24/08/2005 23:04:45
Information générale
Forum:
ASP.NET
Catégorie:
Menus
Versions des environnements
Environment:
VB.NET 1.1
OS:
Windows XP
Divers
Thread ID:
01043684
Message ID:
01043705
Vues:
16
Omar,

Could you please explain what it is you're trying to do? I don't understand why you want to show a context menu on a button click (typically, a context menu is the result of right-click behavior).

In any case, MessageBoxes can sometimes mess up the flow of events and that may be why having two in your click-event messes up the ContextMenu. If you're trying to debug behavior, you may be better off either setting breakpoints and stepping through code, or using System.Diagnostics.Debug.WriteLine().

~~Bonnie

>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
>--------------------------------------------------------------------------------------------
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform