C# - Open Forms With Parameters

I am working on a Customized Main Menu for a game (COD MW2) so I need to know how when somebody clicks on an item (`labe or textbox) it will call another form that will contain some custom parameters, without making a form for each Label/textbox !

It's kinda like the Properties Window in Visual Studio! When I select a label you choose the parameters and stuff.
If you didn't understood what I mean please tell me :)

I've already tried to do this but I failed :/

EDIT:

I just found how to do it but i still don't know how to send the info back to the Form1 and Reload The Form1 .... help me please :))

Upvotes: 0

Views: 3444

Answers (1)

Guestík
Guestík

Reputation: 113

EDIT: Open Forms With Parameters

Form1:

private void label1_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2(label1);
            f2.Show();
            f2.textBox1.Text = label1.Text;
        }

Form2:

public partial class Form2 : Form
    {
        Label x;
        public Form2(Label y)
        {
            InitializeComponent();
            x = y;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            x.Text = textBox1.Text;
        }
    }

Upvotes: 2

Related Questions