I am working on accounting software. It's my school project. There is one main form Form1 and three user controls like uc1, uc2, uc3. 1. uc1 has one label in it 2. uc2 has one button 3. uc3 has one textbox and button
I want to send value of uc3's textbox to uc1's label
I have written following code for that
............uc1 code..............
public String MyText
{
set
{
this.label1.Text = value;
}
}
}
................uc3 code..................
public event EventHandler MyEvent;
public String MyText
{
get
{
return this.TextBox1.Text;
}
}
private void button1_click( ... )
{
if(MyEvent != null)
{
MyEvent(null, null);
}
}
...........uc2 code...........
button_Click( .... )
{
uc3.BringToFront();
}
............Form1 code............
void MainWindow_myevent(Object sender, EventArgs e)
{
this.uc1.MyText = this.uc3.MyText;
}
public Form1()
{
this.uc3.MyEvent += MainWindow_myevent;
}
I have create 2 panels pan1 and pan2 on my Form1 my pan1 will show uc2 when form load and then uc3 when the button on uc2 is clicked where as pan2 will show uc1 on form load.
Now my problem is that, If I call uc1 and uc3 when my Form1 load this code works but if I call uc1 and uc2 when my Form1 load and then I call uc3 by clicking button on uc2, this code is not giving me desired result. Please tell me where I'm wrong.