使用窗体名称公开赛形式的winform appliaction [英] Open form with Form Name in winform appliaction

查看:105
本文介绍了使用窗体名称公开赛形式的winform appliaction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想请问我应该怎么做,以开放的形式在WinForm的C#的帮助或类的名字吗?



我有三个不同的形式




  • UserManagement

  • GroupsManagement

  • LocationManagement



我得到许可从数据库中这三种形式



在菜单中单击我填写标签属性与表单的名称像这样

  tsmMain.Tag = item.PermissionName 
tsmMain.Click + =新的EventHandler(tsmMain_Click);



我想要做的是在点击按钮打开动态的形式和条件,如果除去这些?
我能做到这一点与反思要不然??

  ToolStripMenuItem AA =发件人为ToolStripMenuItem; 
var标记= aa.Tag;
如果(标签==用户管理)
{
UserManagement oUserForm =新UserManagement();
oUserForm.Show();
}
如果(标签==组管理)
{
GroupManagement oGroupForm =新GroupManagement();
oGroupForm.Show();
}


解决方案

您可能能够做到这样的事情,用你的表单的名字,作为一个字符串参数:

  VAR形式=(表格)Activator.CreateInstance( Type.GetType(YourNameSpace.UserManagement)); 
form.Show();


I want to ask what should i do to open form with the help or class name in winform c#?

I have three different forms

  • UserManagement
  • GroupsManagement
  • LocationManagement

I get permission from database for these three forms

in menu click i fill tag Property with the name of form like this

tsmMain.Tag = item.PermissionName
tsmMain.Click += new EventHandler(tsmMain_Click);

what i want to do is to open form dynamically in button click and to remove these if condition? Can i do this with reflection or else??

ToolStripMenuItem aa = sender as ToolStripMenuItem;
        var tag = aa.Tag;
        if (tag == "User Management")
        {
            UserManagement oUserForm = new UserManagement();
            oUserForm.Show();
        }
        if (tag == "Groups Management")
        {
            GroupManagement oGroupForm = new GroupManagement();
            oGroupForm.Show();
        }

解决方案

You may be able to do something like this, using the name of your form, as a string argument:

var form = (Form)Activator.CreateInstance(Type.GetType("YourNameSpace.UserManagement"));
form.Show();

这篇关于使用窗体名称公开赛形式的winform appliaction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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