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

  • SEARCH
  • Home
  • 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 8581903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:09:46+00:00 2026-06-11T21:09:46+00:00

I have produced some code to display each printer installed and online in a

  • 0

I have produced some code to display each printer installed and online in a menu item. But I can not figure how to raise an event when the menu item is clicked. I removed the code where I obtain the printernames because thats not relevant now.

string printerName; // contains the first printer name, later contains 2nd printername. This is variable.

selectprinterNameMenuItem.DropDownItems.Add(printerName); // here do I add the new printer to the menu item.

normally you should be able to add an event to the menu item; but I create it by code, and I do not know the exact name. How can I detect when the menu item is clicked on?

  • 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. Editorial Team
    Editorial Team
    2026-06-11T21:09:47+00:00Added an answer on June 11, 2026 at 9:09 pm

    The Add(String) method of ToolStripItemCollection returns the created ToolStripItem. You can add your event handler to this object:

    string printerName; // contains the first printer name, later contains 2nd printername. This is variable.
    
    ToolStripItem addedItem = selectprinterNameMenuItem.DropDownItems.Add(printerName); // here do I add the new printer to the menu item.
    addedItem.Click += new EventHandler(printerName_Click); // here you register to the click event
    

    EDIT (according to your comment):

    You can tell the printer name that has been clicked using the sender argument passed to the event handler, i.e.:

        void printerName_Click(object sender, EventArgs e)
        {
            ToolStripItem item = (ToolStripItem)sender;
            string printerClicked = item.Text;
    
            // whatever you want based on the printerName
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so I have some code that worked fine in PHP4 but since upgrading
I have some code that creates a multi-dimensional array, but my result seems to
Some premise: a grower grows produce, a produce can have many varieties, but some
I have some code that produces undefined values in an array making no sense.
I have some data (produced by a legacy application) that I know is invalid
I have some HTML that is being produced by a WordPress plugin that is
I have written some code which produces simple animations based on cycling through a
How to selectively display pages on sidebar? I have some pages that i want
I have the following piece of code: class Student { public: Student(){} void display()
For some reason the script below is not working. This is the code I

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.