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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:16:36+00:00 2026-05-27T22:16:36+00:00

I am working on a piano in C#. I have encountered a small problem.

  • 0

I am working on a piano in C#. I have encountered a small problem.

I have a piano keyboard which, when pressed, displays the relevant note on the staff.

The notes created are stored in an array of type PictureBox, called picBox. I have constructed the following event handler, however it is not working.

private void pictureBox_Click(object sender, MouseEventArgs e)
        {
            picBox[0].MouseDown += new MouseEventHandler(pic_Click); //testing for first location
        }

    private void pic_Click(object sender, MouseEventArgs e)
    {
        ClickedTextBox.Text = "I was clicked";
    }

I am just testing to see if the first note was clicked. Why is this not working?

Here is the method which adds the picturebox (containing the note) to the staff (panel3).

public void addPictureBox(int x, int y, Image image)
        {
        picBox[cnt] = new PictureBox();

        picBox[cnt].Image = image;
        picBox[cnt].Location = new Point(x, y);
        picBox[cnt].BackColor = Color.Transparent;

        panel3.Controls.Add(picBox[cnt]);
        picBox[cnt].BringToFront();
        cnt++;
    }

What is wrong with my event handler please? Also, what can I do to identify the location in the array of the picturebox clicked? Thank you

  • 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-27T22:16:36+00:00Added an answer on May 27, 2026 at 10:16 pm

    As said in the first comment, you subscribe to the event in a wrong location.

    Also use the sender parameter of your event handler to know which picturebox is clicked (it’ll contain an instance of the picturebox).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a virtual piano keyboard that processes imported mp3 sound samples. I've
I am working on a semi-piano app with a diffrent keyboard-layout then a usual
Working on a console application using Delphi 7, and have run into a problem.
Working live URL showing problem: http://69.24.73.172/demos/newDemo/test.html The HTML : <div class="small-vote"> <a href="#" class="s
Working with C and Win32, I have a problem where my program freezes instead
Working with a SqlCommand in C# I've created a query that contains a IN
Working on a project at the moment and we have to implement soft deletion
Working with python interactively, it's sometimes necessary to display a result which is some
Working with a Lucene index, I have a standard document format that looks something
Working with SSRS and a SQL 2000 source, I have a stored procedure that

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.