473,395 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

which picture box was clicked?

Hi,

I have 64 pictureboxes that all use the same MouseDown
function. How can I detect which picturebox has been
clicked upon? Can I add an extra parameter to the Event
function?

TIA...John.

gridCell[count].MouseDown += new
MouseEventHandler(gridCell_MouseDown);
...
...
...
private void gridCell_MouseDown(object sender,
MouseEventArgs e)
{
this.textBox1.Text = sender.ToString();
}
Nov 22 '05 #1
4 1518
An easy (although innefficient way) is to iterate through the controls and
try a tit test based on the clicked point. This might work (although I
haven't tested):

Rectangle rect = new Rectangle(0, 0, 1, 1);

PictureBox pictureBoxHit = null;

foreach (PictureBox pictureBox in pictureBoxHashTable.Values)

{

rect.X = e.X;

rect.Y = e.Y;

if (pictureBox.Bounds.IntersectsWith(rect))

{

pictureBoxHit = pictureBox;

break;

}

}

if (pictureBoxHit != null)

{

// Hit code goes here

}


"John McD" <ju*********@hotmail.com> wrote in message
news:08****************************@phx.gbl...
Hi,

I have 64 pictureboxes that all use the same MouseDown
function. How can I detect which picturebox has been
clicked upon? Can I add an extra parameter to the Event
function?

TIA...John.

gridCell[count].MouseDown += new
MouseEventHandler(gridCell_MouseDown);
..
..
..
private void gridCell_MouseDown(object sender,
MouseEventArgs e)
{
this.textBox1.Text = sender.ToString();
}

Nov 22 '05 #2
An easy (although innefficient way) is to iterate through the controls and
try a tit test based on the clicked point. This might work (although I
haven't tested):

Rectangle rect = new Rectangle(0, 0, 1, 1);

PictureBox pictureBoxHit = null;

foreach (PictureBox pictureBox in pictureBoxHashTable.Values)

{

rect.X = e.X;

rect.Y = e.Y;

if (pictureBox.Bounds.IntersectsWith(rect))

{

pictureBoxHit = pictureBox;

break;

}

}

if (pictureBoxHit != null)

{

// Hit code goes here

}


"John McD" <ju*********@hotmail.com> wrote in message
news:08****************************@phx.gbl...
Hi,

I have 64 pictureboxes that all use the same MouseDown
function. How can I detect which picturebox has been
clicked upon? Can I add an extra parameter to the Event
function?

TIA...John.

gridCell[count].MouseDown += new
MouseEventHandler(gridCell_MouseDown);
..
..
..
private void gridCell_MouseDown(object sender,
MouseEventArgs e)
{
this.textBox1.Text = sender.ToString();
}

Nov 22 '05 #3
In the initialization of the gridCell pictureBoxes
you can initialise the unique name to the picture box

if count is unique,

gridCell[count].Name=count.ToString();
gridCell[count].MouseDown += new
MouseEventHandler(gridCell_MouseDown);

private void gridCell_MouseDown(object sender,
MouseEventArgs e)
{
PictureBox pb=(PictureBox)sender; MessageBox.Show(pb.Name);} -----Original Message-----
Hi,

I have 64 pictureboxes that all use the same MouseDown
function. How can I detect which picturebox has been
clicked upon? Can I add an extra parameter to the Event
function?

TIA...John.

gridCell[count].MouseDown += new
MouseEventHandler(gridCell_MouseDown);
...
...
...
private void gridCell_MouseDown(object sender,
MouseEventArgs e)
{
this.textBox1.Text = sender.ToString();
}
.

Nov 22 '05 #4
In the initialization of the gridCell pictureBoxes
you can initialise the unique name to the picture box

if count is unique,

gridCell[count].Name=count.ToString();
gridCell[count].MouseDown += new
MouseEventHandler(gridCell_MouseDown);

private void gridCell_MouseDown(object sender,
MouseEventArgs e)
{
PictureBox pb=(PictureBox)sender; MessageBox.Show(pb.Name);} -----Original Message-----
Hi,

I have 64 pictureboxes that all use the same MouseDown
function. How can I detect which picturebox has been
clicked upon? Can I add an extra parameter to the Event
function?

TIA...John.

gridCell[count].MouseDown += new
MouseEventHandler(gridCell_MouseDown);
...
...
...
private void gridCell_MouseDown(object sender,
MouseEventArgs e)
{
this.textBox1.Text = sender.ToString();
}
.

Nov 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John McD | last post by:
Hi, I have 64 pictureboxes that all use the same MouseDown function. How can I detect which picturebox has been clicked upon? Can I add an extra parameter to the Event function? ...
4
by: Kersten | last post by:
Hi to all, I havea big DB with information and pictures of our employees and this DB is used by a lot of people in our company. The data format is Access2000. In the past the import of pictures...
0
by: wolf | last post by:
Hi I had put a PictureBox and three Buttons on a Form. I want the PictureBox show the 1.gif if I click button1 and show 2.gif if I click button2 and so on. But while it running, the value of...
2
by: Vladimir Oľura | last post by:
I am building a Pocket PC application and I have 5 forms (form1, form2, ....). Form1 starts up and I click a button for Form2 to show up. Form1 is hiden. On Form2 i click a button for Form3 to show...
7
by: Amadelle | last post by:
Hi all and thanks in advance, I am stuck! I can't figure out how to identify which button was clicked on my ASP.NET page in the PostBack event? So what I am trying to do is to is to have an if...
6
by: Jeff | last post by:
Hey (and thank you for reading my post) In visual web developer 2005 express edition I've created a simple website project.. At this website I want users who register to be able to upload a...
3
by: Michael A. Covington | last post by:
How easy is it to extend OpenFileDialog so that when a file is selected (clicked), my code will be called to extract some information from the file and display a picture?
3
by: rn5a | last post by:
Consider the following code which creates LinkButtons dynamically: For i = 1 to 5 lnkBut = New LinkButton lnkBut.ID = "lnkBut" & i lnkBut.Text = i.ToString & " " lnkBut.CommandName = i...
7
by: jambyl | last post by:
I have two JSP pages PageOne.jsp and PageTwo.jsp. On the PageOne.jsp I have TextBoxOne and TextBoxTwo. Next to each of these textboxes there is a "Wizard1" button and "Wizard2" button. When the...
1
by: frozenade | last post by:
Hi.. I am realy new in Java, and I still confuse with some Java features. I have jLabel1 to display picture. I used jButton1 to change picture in jLabel1. I used this code: Image img =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.