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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:36:39+00:00 2026-05-24T15:36:39+00:00

In the program I have multiple panels being created with picture boxes. The picture

  • 0

In the program I have multiple panels being created with picture boxes. The picture boxes are delegated to be clickable. I would like to have the user to have the option to remove one of the panels/picture boxes from the order. Right now if it is removed and the order is rearranged all picture boxes after the one that was removed retains its delegated order. So clicking on any of them after the one that was removed, skips to the one next to it down the line (ie click on #9 and it will go to #10). I need to remove the delegation of the reordered ones and re delegate them correctly. I have tried:

int z2 = z;
var myClickDelegate = (EventHandler)delegate { clicked(z2, null); };
PicBx[z].Click += myClickDelegate;

to create and

PicBx[z].Click -= myClickDelegate;

to remove

and also

int z2 = z;
PicBx[z].Click -= delegate { clicked(z2, null); };

but both of them does not remove the origional delegation.

  • 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-24T15:36:39+00:00Added an answer on May 24, 2026 at 3:36 pm

    Your first method should work, but the later one shouldn’t work.
    because when you do PicBx[z].Click -= delegate { clicked(z2, null); }; method you are not removing the old delegate, instead you are creating a new delegate and then removing it.

    In your first try this should work:

    private void SomeMethod()
    {
        var myClickDelegate = (EventHandler)delegate { clicked(z2, null); };
        PicBx[z].Click += myClickDelegat;
        //Do extra work
        PicBx[z].Click -= mayClickDelegat;
    }
    

    Edit: Pair to your comment:
    I notice that you are only in your delegate adding clicked(z2, null), so I assumed that you are only creating the delegate at the first place just to pass that int z2 to represent the picture box index.
    You can put that index with the picture box itself by using pictureBox.Tag and in the click event get that int from the tag:

    int z2 = z;
    picBx[z].Tag = z2;//here we embedded the number with the picture box.
    PicBx[z].Click += clicked;
    ...
    PicBx[z].Click -= clicked;
    

    And so in the clicked event:

    private void clicked(object sender, EventArgs e)
    {
        PictureBox pictureBox = sender as PictureBox;
    
        if (pictureBox != null)
        {
            int number = Convert.ToInt32(pictureBox.Tag);
            ...
        }
    }
    

    Edit2: As pair to your comments, it seems like you have a different signature of the clicked method:

    private void clicked(int tes,..
    {
        Pnl[tes].BackColor = Color.Red;
    }
    

    Here we only change it to be:

    private void clicked(object sender, EventArgs e)
    {
        PictureBox pictureBox = sender as PictureBox;//when user clicks on picture box it will be the sender parameter.
    
        if (pictureBox != null)
        {
            //we add number to each of picture boxes at there tags. "picBx[z].Tag = z2"
            int tes = Convert.ToInt32(pictureBox.Tag);
            pnl[tes].BackColor = Color.Red;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program in which the user adds multiple objects to a scene.
I have a program in Perl I'm working on where I would need multiple
I have a contact manager program that I'd like to design for multiple network
I have multiple custom NSViews in my Cocoa program. I am looking for a
I have a situation where I might have multiple instances of a program running
I have a C# Winforms program with multiple textboxes. I used the properties for
I have a C# program which will have multiple instances that need to communicate
I have an android program where I have multiple buttons using the same OnClickListener,
In a Java program, I have multiple subclasses inheriting from a parent (which is
I have a program where I have multiple classes derived from a base class.

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.