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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:20:21+00:00 2026-06-15T08:20:21+00:00

I am initializing an array of PictureBox . The matter is, I cannot add

  • 0

I am initializing an array of PictureBox. The matter is, I cannot add individual EventHandler with each. I have this code in a for loop:

picBoxs[i] = new PictureBox();
picBoxs[i].Anchor = AnchorStyles.None;
picBoxs[i].Location = new Point(x, y);
picBoxs[i].Size = new Size(104, 104);
picBoxs[i].SizeMode = PictureBoxSizeMode.Normal;
picBoxs[i].BorderStyle = BorderStyle.FixedSingle;
//this.picBoxs[i].Click += new System.EventHandler(this.picBoxs_Click); //Single EventHandler for all PictureBox(s)
this.picBoxs[i].Click += new System.EventHandler(this.picBoxs[i]_Click); //Generates error

I want picBoxs1_Click(), picBoxs2_Click(), picBoxs3_Click() …(and so on). Because I need EventHandler for each PictureBox. I can make general EventHandler, picBox_Click() without any problem, but doing this I get a method for every PictureBox, I cannot do different stuffs after clicking different PictureBox. Any idea will greatly be appreciated.

Thanks in advance…

Edit:
I want, when I click on a PictureBox, a message box will appear telling me an index of a 2D array. Say my picturebox(s) are arranged like this:

picBox0 picBox1 picBox2

picBox3 picBox4 picBox5

after clicking picBox2: MessageBox will say “[0][2]”, same as clicking picBox4: MessageBox will say “[1][1]” and so 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-15T08:20:22+00:00Added an answer on June 15, 2026 at 8:20 am

    Use a single event handler, like this:

    this.picBoxs[i].Click += picBoxs_Click;
    

    And within that event handler you can look up information about your picturebox:

    void picBoxs_Click(object sender, EventArgs e)
    {
        var box = sender as PictureBox;
        int i = Array.IndexOf(picBoxs, box);
    
        int columnCount = 3;
        int row = i / columnCount;
        int col = i % columnCount;
    
        Messagebox.Show(string.Format("[{0}][{1}]", row, col));       
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read this document Initializing static array of strings (C++)? and tried to
I have a problem initializing an array whose size is defined as extern const.
I have a question in initializing my structure array inside a structure array. for
I am initializing an array like this: public class Array { int data[] =
I have a problem with initializing an array of double with the size determined
I want to check an array in a condition. Let's take this simple code
I'm having a lot of problems initializing an array of bools. When using the
how to take user input in Array using Java? i.e we are not initializing
I have a problem with initialzing a 2D array in python. I want a
When initializing a new Date object in JavaScript using the below call, I found

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.