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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:20:45+00:00 2026-06-10T06:20:45+00:00

I have a Form that contains only 2 things, a PictureBox and a Label

  • 0

I have a Form that contains only 2 things, a PictureBox and a Label.

I added a mouse click event handler to the picture box.

this.pictureBox1.MouseClick += picture_MouseClick;

Inside the handler I need to check if the location of the mouse click is within the bounds of the label. To do this, I am using the mouse event location and checking to see whether that location is within the bounds of the label.

private void picture_MouseClick(object sender, MouseEventArgs e)
{
    if (label1.Bounds.Contains(e.Location))
    {
        MessageBox.Show("FOUND YOU!");
    }
}

I expected this to work as it seems easy enough however the click location (the orange box in the image) that leads to the MessageBox being shown is offset down and to the right of the label.

Form With Label

Is this because the mouse event is relative to the PictureBox and the Label bounds are relative to the Form? Or vice versa?

By the way, the label you see in the image is hidden at runtime. I am just using the label as a “hack” way of knowing if the user clicked in a certain spot.

public Form1()
{
    InitializeComponent();
    this.label1.Visible = false;
    this.pictureBox1.MouseClick += picture_MouseClick;
}

(I tried subtracting the width of the label from e.X and the height of the label from e.Y but that didn’t seem to work.)

Thank you,

Jan

  • 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-10T06:20:47+00:00Added an answer on June 10, 2026 at 6:20 am

    The e.Location is the mouse position (a point) relative to the upper-left corner of the picturebox.
    The Bounds property is relative to the container of the control.
    (And in this case, the container is the form, as you and SLacks have rightly pointed out)

    To check the correct position I will try with this code (now tested)

    Point p = e.Location;
    p.X += pictureBox1.Left;
    p.Y += pictureBox1.Top;
    if(label1.Bounds.Contains(p))
       .....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that contains a TOpenDialog component ( OpenDialog1 ) and a
I have a form that contains dataGridView, whose coloumn are set to dgrv1.Width =dgrv1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible)+20;
i have a form that contains checkboxes. I've named the checkboxes as stream[], so
Say I have a form that contains a drop-down list populated by values stored
I have a form MainForm which is a Windows Forms form that contains many
I need to make the program which have one form that contains PNG image
I have created a form that contains fields used to accept a floating value
I have a form wizard that contains 3 forms. Basically, what I am trying
i have a windows form that contains a bunch of textboxes. I need a
I have a model form that contains a DecimalField() with max_digits set to 5.

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.