Click here to Skip to main content
15,921,837 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have one form say Form1 and a custom user control, that i made myself having textbox and a button. when i click in the button of my custom user control another form appears say Form2 having button and label. in the button click event of the from 2 i want the value of label of form to in textbox of my custom user control. Thanks in advance for you answer :).
Posted

1 solution

Put a public event on Form1 that will take some text as an argument and update your custom control with that text.

When you display Form2 be sure to set the Owner as Form1

Then from the button click event on Form2 call the event on Form1 with the text on Form2

For example on Form1 I have placed a Button1 which displays a Form2...
C#
private void button1_Click(object sender, EventArgs e)
{
    Form2 f2 = new Form2();
    f2.Show(this);
}

I also created an event on Form1 ...
C#
public void AnEvent(string text)
{
    MessageBox.Show(text);   // replace this with the update to your custom control
}

On Form2 I also have a button1 that does this...
C#
private void button1_Click(object sender, EventArgs e)
{
    Form1 f = (Form1)this.Owner;
    f.AnEvent("My text");
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900