如何知道哪个表单在vb.net中称为另一个表单?

0 vb.net

我有提供查找按钮的多个表单.我有的表单是Contacts.vb和Users.vb,我想对这两种表单使用单个Find.vb表单.我的意思是用户是否按下Contacts.vb或Users.vb中的查找按钮,应该打开相同的表单,并使用从数据库中提取的相应数据.

我尝试使用Find.Owner = MeUsers.vb,但我不知道如何从Find.vb确定谁是所有者.

我尝试使用它,如果查找表单的所有者是Users.vb然后从users表获取数据,如果owner是Contacts.vb,则从Contacts表中获取数据.不幸的是,我无法执行此任务.

请提供任何适当的解决方案或任何其他建议来执行此操作.提前致谢

小智 8

使用以下方式致电您的孩子

frmChildren.ShowDialog(Me)
Run Code Online (Sandbox Code Playgroud)

现在,如何知道调用父表单的表单?使用:

Me.Owner.Name
Run Code Online (Sandbox Code Playgroud)

例如...

if Me.Owner.Name = "frmMain" then
   MessageBox.Show("YES! Its called from frmMain")
else
   MessageBox.Show("Its called from " & Me.Owner.Name)
End If
Run Code Online (Sandbox Code Playgroud)

也许你需要这个:

'To call your form Find.vb from a command button. (for example)
Find.ShowDialog(Me)

'How to know which form call to Find.vb ?
If Me.Owner.Name = "Contacts" then
   'Actions for Contacts
ElseIf Me.Owner.Name = "Users" then
   'Actions for Users
else
   'Actions for NOT"Contacts" and NOT"Users"
end if
Run Code Online (Sandbox Code Playgroud)