473,382 Members | 1,689 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,382 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 1517
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.