如何通过.dll文件到达另一个项目的表单? [英] How to reach to a form that is another project by means of .dll file?

查看:62
本文介绍了如何通过.dll文件到达另一个项目的表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#项目上为winforms创建了一个自定义标签控件,并将控件导出为dll文件。有一些方法可以找到我项目中的所有表单,这些方法不适用于导入dll文件的项目。如何在上一个项目中找到所有表单?

I created a custom label control for winforms on my C# project and exported the control as dll file. There is some methods which find all forms on my project and those methods don''t work on project where imported dll file. How can i find all forms the last project?

推荐答案

您可以将dll添加为另一个项目的引用并重用所有公共类。在您的情况下,检查您是否添加了引用以及控件是否设置为公共。
You can add the dll as a reference to another project and reuse all the public classes. In your case, check if you have added the reference and if the control is set as public.


public List FindAllFormsOnProject()

{

列表foundForms = new List();

类型[] typesOnProject = Assembly.GetExecutingAssembly()。GetTypes();

foreach(类型提示在typesOnProject中)

{

if(tip.BaseType == typeof(Form))

{

试试

{

表格frm =(表格)Activator.CreateInstance(小费);

foundForms.Add(frm);

}

catch(例外情况)

{



MessageBox.Show(ex.Message);

}

}

}

返回foundForms ;

}





我用来查找项目中所有表单的方法。正如我所说,不适用于包含.dll文件的其他项目。
public List FindAllFormsOnProject()
{
List foundForms = new List();
Type[] typesOnProject = Assembly.GetExecutingAssembly().GetTypes();
foreach (Type tip in typesOnProject )
{
if (tip.BaseType == typeof (Form))
{
try
{
Form frm = (Form)Activator.CreateInstance(tip);
foundForms.Add(frm);
}
catch (Exception ex)
{

MessageBox.Show(ex.Message);
}
}
}
return foundForms;
}


Method what i use to find all forms in my project. As i said, doesn''t work on other project that includes .dll file.


这篇关于如何通过.dll文件到达另一个项目的表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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