VB.NET使用sub打开表单的新实例 [英] VB.NET Open new instance of a form using a sub

查看:72
本文介绍了VB.NET使用sub打开表单的新实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过子/函数打开表单的新实例?

如果我指定表单我可以这样做,我遇到的问题是将表单传递给sub ...



我正在努力做一些事情......

Is there a way to open a new instance of a form via a sub/function?
I can do it if I specify the form, problem I'm having is passing the form to a sub...

I'm Trying to do something to the effect of...

' This works if I specify the form
Dim NewInstance as New frmTest
NewInstance.Show

' I've tried a dozen ways to get this to work and nadda

   OpenNewInstanceOfForm(frmTest)

Sub OpenNewInstanceOfForm(F as form)
  Dim NewInstance as New F
  NewInstance.Show
End sub



每当我尝试使用F时,它都表示未定义



任何人?



谢谢!


Every time I try to use F, it says it's undefined

Anyone?

Thanks!

推荐答案

Dim NewInstance as New F 会产生问题,因为F不是一个类,而是一个指向实例的变量。

尝试将新的实例作为新的frmTest
Dim NewInstance as New F will create a problem since F is not a class but rather a variable pointing to an instance.
Try Dim NewInstance as New frmTest

Pass典型将该方法的形式作为参数,然后使用Activator.CreateInstance创建该类型的示例。将其转换为Form,然后调用Show。

或者,传递表单类的名称,并使用字符串版本的Activator.CreateInstance来创建它。

https://msdn.microsoft.com/en-us/library/ d133hta4(v = vs.110).aspx [ ^ ]
Pass the Type of the form to the method as a parameter, then use Activator.CreateInstance to create an example of the type. Cast that to a Form, and call Show on that.
Alternatively, pass the name of the form class, and use the string version of Activator.CreateInstance to create it.
https://msdn.microsoft.com/en-us/library/d133hta4(v=vs.110).aspx[^]


这篇关于VB.NET使用sub打开表单的新实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆