Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Showing a contextMenu
Message
De
20/03/2003 10:25:50
 
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
00767833
Message ID:
00768075
Vues:
14
Glad you figured it out, Kirk. I see what you're doing now. The way I've handled it in the situation you have (context menu for a user control) is to *still* have a ContextMenu on the form. The event-handler for the ContextMenuPopup (which was where I was adding menu items) will tell you from which control the right-click was detected.
  if (this.oContextMenu.SourceControl == MyUserControl)
  {
    // put code here to add your menu items
  }
From there, you can call methods on the user control that will handle populating the context menu if you need to. The item Click handler can also call methods on the UserControl ... so basically all your functionality for how the context menu should work *is* in your user control, but you since you put the ContextMenu on the Form, you don't have to mess with MouseDown events to figure out when a right-click happened on your control because that's what the ContextMenu itself does.

I don't know if I've explained this very well (and VB could very well be different than C# in this respect, I don't really know), but I suspect that if you've got it working one way, you probably don't want to try it my way. =)

~~Bonnie


>*Update: I got it: Me.ContextMenu1.Show(Me, New Point(e.X, e.Y))
>
>Bonnie
>
>Thanks for the stab. But I think I need the step right before your code. I have the following event:
>
>
>Private Sub Schedule1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Schedule1.MouseDown
>        If e.Button = MouseButtons.Right Then
>            'Me.ContextMenu1.Show(me.ContextMenu1,e.X )     <<==== this line doesn't work.
>
>        End If
>End Sub
>
>
>So, basicly this is the event based off a user form control. If it is a right-click event I want to actually display my menu. I don't know how to actually make the menu pop up on the screen. I think your code adds the menu items to the menu and then captures which menu option they clicked. But from the event above I first need to get the menu to display on the screen. All the help I've read shows to link it to the contextmenu property of a form control. But this is a user-control without that property.
>
>Thanks for all the help
>
>Kirk
Bonnie Berent DeWitt
NET/C# MVP since 2003

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

Click here to load this message in the networking platform