Hello World 0

Hello World 0

  • NA
  • 23
  • 72k

Creating buttons to launch a app or folder but read the date from a xml or ini

Jan 5 2011 2:17 PM
Hi, i'm new to programming(but i know 1 scripting language) and need some help.

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);

                xCo += 50;
                button1.Location = new Point(xCo, 30);
                //read the Text-key in the ini or xml file;
                button1.Text = "Text";
                this.Controls.Add(button1);
                //read what progress should be executed in and pass it on to the eventhandler?;
                button1.Click += new EventHandler(button1_Click);
            }
        }


        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Event Triggerd");
            //start the corrent procces;
            System.Diagnostics.Process.Start("notepad.exe");
        }

        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.Run(new Form1());
        }
    }
}

Thx.


Answers (5)