获取项目中的所有表单到用户控件的属性组合框 [英] Get All Forms In a Project To User Control's Property Combo Box

查看:95
本文介绍了获取项目中的所有表单到用户控件的属性组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个用户控件,我想创建一个dll并在其他项目中使用它。



我在该用户控件中有属性,应该在propertygrid中显示一个组合框,包含引用项目中的所有表单。我必须选择其中一个表单来设置物业价值。



我创建了以下自定义UITypeEditor



Hi,

I have a user control which I want to create a dll and use it in other project.

I have Property in that user control which should show a combo box in propertygrid contains all forms in the referenced project.I have to select one of that form to set the property value.

I Created the following custom UITypeEditor

internal class EntryFormEditor : ObjectSelectorEditor
      {
          protected override void FillTreeWithData(Selector theSel,
            ITypeDescriptorContext theCtx, IServiceProvider theProvider)
          {
              base.FillTreeWithData(theSel, theCtx, theProvider);  //clear the selection
              GrbDataGridView aCtl = (GrbDataGridView)theCtx.Instance;

              Type formType = typeof(Form);
              try
              {
                  //foreach (Assembly currentassembly in AppDomain.CurrentDomain.GetAssemblies())
                  //{
                  foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
                      {
                          if (formType.IsAssignableFrom(type))
                          {
                              try
                              {
                                  SelectorNode aNd = new SelectorNode(type.Name, type);

                                  theSel.Nodes.Add(aNd);
                              }
                              catch (Exception ex)
                              {
                              }
                              //if (type ==(Form) aCtl.EntryFormName)
                              //    theSel.SelectedNode = aNd;
                          }
                      //}
                  }
              }
              catch (Exception ex)
              {
              }
          }
      }







但是只显示dll中的表单而不是引用的项目





我做错了什么任何人都可以帮忙吗?




but showing only the forms inside the dll and not in the referenced project


What did I done wrong . Can anyone please Help ?

推荐答案

尝试 Assembly.GetEntryAssembly 而不是 Assembly.GetExecutingAssembly


在这一行

In this line
foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())



你指的是正在执行的程序集(你的dll)。将其更改为您要检查的实际装配。





看看 GetCallingAssembly [ ^ ]。

看起来你可以在dll的入口点使用它获得立即调用方法的程序集。该链接指出了一些怪癖。



而且,由于我不知道你的应用程序的控制流,它也可以返回属于.NET框架的一些程序集。

[/编辑]


you're referring to the executing assembly (your dll). Change it to the actual assembly that you want to inspect.


Have a look at GetCallingAssembly[^].
Looks like you could use it in your dll's entry point to get the assembly of the immediate calling method. The link states some quirks, though.

And, since I have no idea of your application's control flow, it could as well return some assembly belonging to the .NET framework.
[/Edit]


这篇关于获取项目中的所有表单到用户控件的属性组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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