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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:04:41+00:00 2026-06-02T20:04:41+00:00

Just starting out on C# and I keep getting stuck on this particular piece

  • 0

Just starting out on C# and I keep getting stuck on this particular piece code (more precisely the lblArr[i, j].Click += pnlArr_Click; line):

public void CreateLabelArray(int height, int width, int nrofShips)
    {
        pnlBase.Controls.Clear();
        lblArr = new Label[height, width];
        int xpos = 0;
        int ypos = 0;

        for (int j = 0; j < width; j++)
            {
            int column = j + 1;
            for (int i = 0; i < height; i++)
                {
                Coordinaat pos = new Coordinaat();
                pos.X = j;
                pos.Y = i;
                lblArr[i, j] = new Label();
                lblArr[i, j].Left = xpos;
                lblArr[i, j].Top = ypos;
                lblArr[i, j].Width = 35;
                lblArr[i, j].Height = 35;
                lblArr[i, j].Tag = pos;
                lblArr[i, j].Click += pnlArr_Click;
                lblArr[i, j].BackColor = System.Drawing.Color.LightBlue;
                lblArr[i, j].BorderStyle = BorderStyle.FixedSingle;

                pnlBase.Controls.Add(lblArr[i, j]);
                xpos += 0;
                ypos += lblArr[i, j].Height;

                }
            xpos += 35;
            ypos = 0;
            }
    }

As I am trying to find out what particular mouse button was pressed on a label in an array, I thought this method might work:

public int pnlArr_Click(object sender, MouseEventArgs e)

The error goes away if i change MouseEventArgs to EventArgs, but then this won’t work anymore:

if (e.Button == MouseButtons.Left)

Any ideas? all help is much appreciated.

  • 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-02T20:04:43+00:00Added an answer on June 2, 2026 at 8:04 pm

    The event that receive a MouseEventArgs as second argument is not the Click event,
    but the MouseDown. Change your code in this way (also, to better readability, rename the event handler in pnlArr_MouseDown)

    lblArr[i, j].MouseDown += pnlArr_Click; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just starting out with mongo and python and am stuck on getting this
Just starting out with C#, so this may be overly simple that I keep
Just starting out, this should be a simple one but I haven't been able
I am just starting out with Python and decided to try this little project
Just starting out in asp.net. Have just created a login.aspx page in my site
Just starting out with subversion, have set up repos for 3 current projects and
I'm just starting out with HTML and Dreamweaver. Basicly, I'm trying to create a
I am just starting out with DI & unit testing and have hit a
I am just starting out with Silverlight (2 RC0) and can’t seem to get
So I am just starting out developing PHP web applications and have finished setting

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.