怎样,我可以从vb.net 2008项目获得表单名称吗? [英] How, can i get forms name from vb.net 2008 project?

查看:95
本文介绍了怎样,我可以从vb.net 2008项目获得表单名称吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,我已经使用vb.net 2008创建了小程序我希望在运行时从项目解决方案中获取所有表单名称,请给我代码。

i认为代码看起来像这样







Dear all i have created small program using vb.net 2008 i want to get all form names from project solution at run time please give me code.
i think code look like this



private sub proshowformnames()
  For Each FRM As Form In Application.OpenForms
     MsgBox(FRM.Name)
  Next
end sub 







以上代码运行完美

i需要在运行时使用这个紧密的表格名称



代码块添加 - OriginalGriff [ / edit]




above code is runing perfectly
i need like this close form names at runtime

[edit]Code block added - OriginalGriff[/edit]

推荐答案

简单,用

替换MsgBox行
Simple, replace the MsgBox Line with
FRM.Close()


只是警告:我不确定你真的需要 Form.Name 。在运行期间,此属性没有任何意义;它仅对Designer有用。如果你这样做只是为了学习目的,那没关系。



以为你最了解这一点。



此外,请注意,关闭表单最终将关闭应用程序,甚至可能在您遍历所有表单之前(操作顺序未定义)。您可能需要检查每个来自主表单并跳过主表单。



-SA
Just a warning for you: I'm not sure you really need Form.Name. During run-time, this property means nothing; it's only useful for Designer. If you do it just for learning purposes, that's fine.

Thought you better know this.

Also, please be advised that closing the form will eventually close the application, may be even before you traverse all forms (the order of operation is not defined). You may want to check each from to be your main form and skip the main form.

—SA

Dim myAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
        Dim types As Type() = myAssembly.GetTypes()
        For Each myType As Object In types

            If myType.BaseType.FullName.ToString.ToUpper = "SYSTEM.WINDOWS.FORMS.FORM" Then
                MessageBox.Show(myType.Name)
            End If
        Next









Arabicturgeman





Arabicturgeman


这篇关于怎样,我可以从vb.net 2008项目获得表单名称吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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