I have a main form named: MainForm and a child form named: ChildForm I want to fill ChildForm's textboxes and in MainForm_ButtonClick i want to fire ChildForm_ButtonClick event.
ChildForm:
public partial class ChildForm :Form
{
public delegate void delPassData(TextEdit text);
private void button1_Click(object sender, EventArgs e)
{
string depart = "";
MainForm mfrm = new MainForm();
delPassData del = new delPassData(frm.funData);
del(this.Item_CodeTextEdit);
}
}
MainForm:
public partial class MainForm : Form
{
public void funData(TextEdit txtForm1)
{
string ss = "";
ss = txtForm1.Text;
MessageBox.Show(ss);
}
private void NavigationPanelBtns_ButtonClick(object sender, ButtonEventArgs e)
{
switch (e.Button.Properties.Caption)
{
case "Save":
// i want to call funData() here but i get an empty messageBox
break;
}
}
}
Child form
Create a Parent Form
To access a textbox in another form:
Set
Modifier
property of the the textbox topublic
in child form.In main form, access the textbox by an object of the child form.
Eg:
To access an event in another form:
Set the event handling function to
public
.Invoke the function by passing
null
as parameters by the object of the form.Eg: