blah blah blah is here! blah blah » Close

up1down
link

Dear All,

I am still new in C#. Is it possible to pop up a form with a trackbar and some textboxes? From this pop up, I want to obtain some data.

Kindest Regards,




E

last answered one year ago

1 answers

link

Well just design your pop-up form (Form2 say) in the normal way and display it from the main form with this code:

// add this private field 
private Form2 f2 = null;

// within a button click handler, say
private void button1_Click(object sender, EventArgs e)
{
if (f2 == null)
{
f2 = new Form2();
f2.FormClosed += Form2_FormClosed;
}
f2.ShowDialog();
}

// add this handler to main form manually, not from designer
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
// get text from textbox1 on Form2
TextBox tb = (TextBox)f2.Controls["textBox1"];
// display it in a label on main form, say
label1.Text = tb.Text;
}

thanks vulpes..at the beginning I used the formclosed from the designer and i wondered how to move it to the source code of form1.cs :)

Feedback