将字符串变量转换为表单对象 [英] Convert String Variable into Form Object

查看:106
本文介绍了将字符串变量转换为表单对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想在Windows Form对象中转换我的字符串变量
因为我想调用Form.Show()方法,并且表单名称在变量中.

在此先感谢

Hi,

I want to convert my string variable in Windows Form object
Because I want to call Form.Show() method and form name is in variable.

Thanks in advance

推荐答案

您应该看看 ^ ]

文章中有一个很好的例子,但这就是表单已经打开的情况

如果没有,那么此代码段将有所帮助

You should have a look at my.application.openforms[^]

There is a good example in the article, but that is if the form is already open

If not then this code snippet will help

Public Function GetForm(ByVal Formname As String) As Form
        Dim t As Type = Type.GetType(Formname) ', True, True)
        If t Is Nothing Then
            Dim Fullname As String = Application.ProductName & "." & Formname
            t = Type.GetType(Fullname, True, True)
        End If
        Return CType(Activator.CreateInstance(t), Form)

    End Function


为什么要存储表格字符串中的名称?你不想那样做.您可以直接调用from.Show()方法.
Why are you storing form name in string? You don''t want to do that. You can directly call the from.Show() method.


拥有一个可变字符串来确定要打开的形式对我来说并不是一个好主意.

为什么没有一些枚举类型供用户选择,然后由哪种枚举类型确定要打开的表单?
Having a variable string from which you determine what form to open doesn''t sound like a good idea to me.

Why not have some enumerated types from which the user can select which then determines which form to open?


这篇关于将字符串变量转换为表单对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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