How define, what form called current Form in C#? [closed]
How to define which form is the current Form in C#? don't use parameters of construction and attribute like as parent form
You could use a constructor that will allow to pass the calling form. For example:
public class Form2: Form
{
private readonly Form _callingForm;
public Form2(Form callingForm)
{
_callingForm = callingForm;
}
...
}
and then in the calling form:
Form2 form2 = new Form2(this);
form2.ShowDialog();
Other than that there might be some forms like the main form for example which are not called from other form.
Or you can define public property in child form, for example called parent
, and show child using
ChildForm form = new ChildForm();
form.parent=this;
form.Show();
精彩评论