find form instance from other class

前端 未结 2 1718
太阳男子
太阳男子 2020-12-18 00:37

I have Main form with list of data inside listBox. On button click I\'m opening new form to create new data object (Main form is inactive in background), when new data is su

2条回答
  •  眼角桃花
    2020-12-18 01:24

    if you call

    Form1.ShowDialog(this)
    

    then you'll be able to get a reference to the calling form with

    this.Owner.Name
    

    in the second form (Form2 in your case)

    see http://msdn.microsoft.com/en-us/library/system.windows.forms.form.showdialog.aspx

提交回复
热议问题