动态显示表单 [英] Dynamically show forms

查看:27
本文介绍了动态显示表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮我解决这个问题.我有一个带按钮的动态菜单.每个按钮都有表单名称(VP、VZPAL、PAL、...).当我点击某个按钮时,我想激活与按钮名称相同的表单.我尝试用这段代码来做,但它有例外:

Please I need help with this issue. I have a dynamic menu with buttons. Each button has name of form(VP,VZPAL,PAL,...).and when I click on some button, I want to activate form with the same name that the button has. I try do it with this code, but its escape with exception:

值不能为空.

string Formname = "FISpanel.Form" + b.Name.ToUpper().ToString();
Form frm =  (Form)Activator.CreateInstance(Type.GetType(Formname));
frm.Show();

Formname 的值是 right(FISpanel.FormVP).有什么想法吗?

Value of Formname is right(FISpanel.FormVP).Any ideas?

推荐答案

这就是我过去实现相同目标的方式.在我的应用程序中,我在 .ini 文件中设置了链接",但每个用户的链接可能不同,因此(像您一样),我需要一个解决方案,根据点击的内容启动表单:

This is how I've achieved the same thing in the past. In my application I have 'links' that are set inside of .ini files, but these can be different for each user, so (like you), I needed a solution that would launch forms depending on what was clicked:

        LinkLabel lnk = (LinkLabel)sender;

        Type type = Type.GetType("Valhalla." + lnk.Tag.ToString());
        Form thisFrm = (Form)Activator.CreateInstance(type);

        // DISPLAY THE FORM //
        thisFrm.ShowDialog();

此外,正如@King King 所提到的.点非常重要.您的表单是否实际命名为:FormVP"或只是VP"(等等...)如果后者那么您将不得不将它们称为:Form.VP 而不是 FormVP.

Also, as @King King has mentioned. The dot is very important. Are your forms actually named: "FormVP" Or just "VP" (etc...) If the later then you will have to call them as: Form.VP and not FormVP.

这篇关于动态显示表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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