I'm trying to create a gui(windows form).
It should do is this:
-read a ini(or xml) file. The ini contains the buttons text and what program or folder should be executed.
-display the button.
-when you press the button or picturebox open the program or folder.
I can display the buttons and pictureboxes but they all trigger the same event.. So my question is:
How can i know what program should be executed when i press the button?
This it the code:
using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace FormWithButton {public class Form1 : Form {public Button button1; public Form1() {int xCo = 10; //read how many time the loop should execute in the ini or xml file; for (int i = 0; i < 3; i++) {button1 = new Button(); button1.Size = new Size(40, 40); |
Thx.
Kevin AungPosted Jan 5, 2011, 6:01 PM
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.
Hello World 0Posted Jan 5, 2011, 6:19 PM
Hello World 0Posted Jan 5, 2011, 5:14 PM
but what should i do when i don't use buttons but PictureBoxes
Kevin AungPosted Jan 5, 2011, 4:28 PM
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;
}
}
FroglegPosted Jan 5, 2011, 4:03 PM
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