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 4083868
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:22:03+00:00 2026-05-20T18:22:03+00:00

Using a separate class which is being made reusable, need to pass it a

  • 0

Using a separate class which is being made reusable, need to pass it a function which would be called on the click event from the context menu…

Problem : Functions aren’t type EventHandlers…. also Different EventHandlers require different paramters inside… e.g. the OnClose for the exit button….

Edit:

In the Class X

public void AddMenuItem(String name, EventHandler target )
    {
        MenuItem newItem = new MenuItem();
        newItem.Index = _menuItemIndex++;
        newItem.Text = name;
        newItem.Click += target;

        _contextMenu.MenuItems.Add(newItem);
    }

In the Wpf:

addToTray.AddMenuItem("&Exit", Exit); 

I would love it to link to the following method but at this point any method would do fine.

private void ShouldIExit(object sender, System.ComponentModel.CancelEventArgs e)
    {
        // checks if the Job is running and if so prompts to continue
        if (_screenCaptureSession.Running())
        {
            MessageBoxResult result = System.Windows.MessageBox.Show("Capturing in Progress. Are You Sure You Want To Quit?", "Capturing", MessageBoxButton.YesNo);
            if (result == MessageBoxResult.No)
            {
                e.Cancel = true;
                return;
            }
        }
        _screenCaptureSession.Stop();
        _screenCaptureSession.Dispose();
    }
  • 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-05-20T18:22:03+00:00Added an answer on May 20, 2026 at 6:22 pm

    I’m guessing that the problem is that your ShouldIExit method does not match the EventHandler delegate. Try changing it to take a regular EventArgs parameter, and see if that works. It’s best to avoid reusing the same event handler for different event types. You should encapsulate common code into separate methods, and then have different handlers call that code.

    private bool CheckExit()
    {
        // checks if the Job is running and if so prompts to continue
        if (_screenCaptureSession.Running())
        {
            MessageBoxResult result = System.Windows.MessageBox.Show("Capturing in Progress. Are You Sure You Want To Quit?", "Capturing", MessageBoxButton.YesNo);
            if (result == MessageBoxResult.No)
            {
                return false;
            }
        }
        _screenCaptureSession.Stop();
        _screenCaptureSession.Dispose();
        return true;
    }
    
    private void ExitButtonClicked(object sender, System.ComponentModel.CancelEventArgs e)
    {
        if (!CheckExit())
        {
            e.Cancel = true;
        }
    }
    
    private void ExitMenuItemClicked(object sender, EventArgs e)
    {
        CheckExit();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the Qt Visual studio integration, adding a new Qt class adds two separate
How would I go about spawning a separate process using a SQL Server 05/08
I'm looking at an existing site and they are using separate databases. The databases
trying to implement a dialog-box style behaviour using a separate div section with all
i'm currently using File::Basename fileparse to separate out a file's directory, base file name
I've been using Eclipse with each project in a separate window by right clicking
I'm building a PHP application using the data mapper pattern to separate my DB
I´m trying to separate a gridViewColumn into two rows. Im using default style for
I have a WCF client/server app which is communicating over HTTP using the WSHttpBinding.
I'm building an ASP.Net website. I have a cart class which stores the items

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.