开发者

How define, what form called current Form in C#? [closed]

开发者_如何学C It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜