How to determine a Form is opened by which Form in .NET?

Posted by Admin L in .NET Programming on 27-08-2012. Tags: , , , , , , , ,

Author: Nosa Lee
Original Address: https://www.seeksunslowly.com/how-to-determine-a-form-is-opened-by-which-form-in-net
To reprint this article, please indicate the source, thank you.
_____________________________________

Usage Scenarios
For instance: there is a public FormA that used to input password, it may be opened by many other Forms.

And in FormA, maybe there is the code that used to operate the calling Form, at this time, you must determine which Form opened FormA.

Method
Very easy. The Form class has Show() and ShowDialog() methods, these methods can contain a parameter that indicates the owner of the opened Form.

General Usage
Just write FormA.Show(Me) or FormA.ShowDialog(Me) in the Form that need to open FormA.
At that time, in FormA, you can get the Form that opened FormA via Me.Owner.Name

Sample Code
[cc lang=”vbnet”]
If Me.Owner.Name = “MainFormA” Then

Else

End If
[/cc]

【赞赏 / Reward】

微信         支付宝         PayPal

Post a comment