Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 129387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:46:55+00:00 2026-05-11T05:46:55+00:00

I have a context menu with a few items. One of the items has

  • 0

I have a context menu with a few items. One of the items has a submenu (or whatever it’s called) with a few items (depends on what files it finds).

What I want to do is when I left click one of the sub-items I want one thing to happen, and when I right click I want another thing to happen.

My problem is that when I use the filesToolStripMenuItem_DropDownItemClicked, I don’t get any MouseEventArgs in the parameter, so I can’t find out which mouse button was used to click the item.

I tried adding it myself in the parameter but I get some error then.

Does anyone know how I can fix this? So I can find out what mouse button was used to click the sub-item (which is a ToolStripMenuItem)?

Thanks

edit: here is the code I use to create the sub items:

IPHostEntry ipE = Dns.GetHostEntry(Dns.GetHostName()); IPAddress[] IpA = ipE.AddressList; for (int i = 0; i < IpA.Length; i++) {       if (!IpA[i].ToString().Contains(':'))            cxItems.Items.Add(new ToolStripMenuItem(IpA[i].ToString())); } 

And for those items I want to be able to do different things depending on which mouse button I use

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:46:56+00:00Added an answer on May 11, 2026 at 5:46 am
     private void button2_Click(object sender, EventArgs e)     {         ToolStripMenuItem item1 = new ToolStripMenuItem('Menu1');         ToolStripMenuItem subMenuitem1 = new ToolStripMenuItem('SubMenu');         item1.DropDownItems.Add(subMenuitem1);         this.contextMenuStrip1.Items.Add(item1);         subMenuitem1.MouseDown += new MouseEventHandler(subMenuitem1_MouseDown);         this.contextMenuStrip1.Show(this.button2,new Point(0,0));     }      void subMenuitem1_MouseDown(object sender, MouseEventArgs e)     {         //e.Button will determine which button was clicked.         MessageBox.Show(e.Button.ToString());     } 

    That should help get you started.

    RE: You’re edit:

    The problem is, you’re just saying new ToolStripMenuItem(IpA[i].ToString()) without keep a reference to it. Here’s how you need to do it:

     IPHostEntry ipE = Dns.GetHostEntry(Dns.GetHostName());     IPAddress[] IpA = ipE.AddressList;     for (int i = 0; i < IpA.Length; i++)     {           if (!IpA[i].ToString().Contains(':'))           {                ToolStripMenuItem subItem = new ToolStripMenuItem(IpA[i].ToString());                subItem.MouseDown += new MouseEventHandler(subItem_MouseDown);                cxItems.Items.Add(subItem);           }     }      void subMenuitem1_MouseDown(object sender, MouseEventArgs e)     {           //get a reference to the menu that was clicked           ToolStripMenuItem clickedMenu = sender as ToolStripMenuItem;           //e.Button will tell you which button was clicked.     } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have the context menu of links provide me an option to
I have a ViewPagerActivity with two views. I want to register a context menu,
I have a context menu with a few selections. If the user picks a
My app has a few activities, all have an options menu, which is the
I have a context menu. It's bound to some collection and it has a
so I have attached a context menu (right-click menu) to a wpf listview. unfortunately,
I have hooked up a context menu item in a listbox item such that
I have a ViewModel (AbstractContextMenu) that represents my context menu (IContextMenu), and I bind
I have a button which opens a context menu with a list of various
I have a problem with a Context menu in JavaFx 2:it never disappers when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.