switch (myPicBox.Name.ToUpper()) { case "PICTUREBOX1": // Form logic break; case default: break; } }
You'll just have to make sure you don't use this event handler for other objects besides Picturebox. The casting will throw an error.
0
FroglegRank #1,020 · 1.9K reputationPosted Jan 5, 2011, 11:03 AM EST
0
Use settings in C# To add to settings open project properties and on the left hand side select settings where you can enter a number of variables which are easily saved I included a screen shot of settings to help you
Kevin Aung46 reputationPosted Jan 5, 2011, 11:28 AM EST
0
In your button1_Click method, try doing sender.ToString(). This should give you the object type with the Text of the button (comma separated). You could parse the sender.ToString() to extract the text of the button and use it in a switch statement to execute the custom method.
Kevin Aung46 reputationPosted Jan 5, 2011, 1:01 PM EST
private void pictureBox1_Click(object sender, EventArgs e)
{
PictureBox myPicBox = (PictureBox)sender;
switch (myPicBox.Name.ToUpper())
{
case "PICTUREBOX1":
// Form logic
break;
case default:
break;
}
}
You'll just have to make sure you don't use this event handler for other objects besides Picturebox. The casting will throw an error.
FroglegRank #1,020 · 1.9K reputationPosted Jan 5, 2011, 11:03 AM EST
To add to settings open project properties and on the left hand side select settings where you can enter a number of variables which are easily saved
I included a screen shot of settings to help you
Kevin Aung46 reputationPosted Jan 5, 2011, 11:28 AM EST
private void button1_Click(object sender, EventArgs e)
{
string[] senderInfo = sender.ToString().Split(",".ToCharArray());
string[] buttonTextInfo = senderInfo[1].Split(":".ToCharArray());
string buttonText = buttonTextInfo[1].Trim();
switch (buttonText.ToUpper())
{
case "OPEN":
// Code logic
break;
case default:
break;
}
}
Hello World 023 reputationPosted Jan 5, 2011, 12:14 PM EST
but what should i do when i don't use buttons but PictureBoxes
Hello World 023 reputationPosted Jan 5, 2011, 1:19 PM EST