如何在自定义控件的属性网格中获取OpenFileDialog?

kar*_*ins 9 .net c# propertygrid controls

我正在创建.net自定义控件,它应该能够加载多个文本文件.我有一个名为ListFiles的公共属性,其中包含以下属性:


[Browsable(true), Category("Configuration"), Description("List of Files to Load")]
public string ListFiles
  {
     get { return m_oList; }
     set { m_oList = value; }
  }
Run Code Online (Sandbox Code Playgroud)

根据对象的类型(string,string [],List,...),属性网格将允许用户输入一些数据.我的目标是在我的组件的属性网格中有一个过滤的openfiledialog这将使用户能够选择多个文件并将其作为数组或字符串(或其他东西......)返回.

Sooo ...这是我的问题:如何在自定义控件的属性网格中获得OpenFileDialog?

非常感谢!

小智 13

您可以使用内置的UITypeEditor.它被称为FileNameEditor

[EditorAttribute(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))]

public string SomeFilePath
{
 get;
 set;
}
Run Code Online (Sandbox Code Playgroud)

  • 您将需要添加System.Design.dll引用.System.Design.dll仅在您定位.net framework 4.0(完整版)而非4.0客户端配置文件时可用 (6认同)

Cor*_*ory 10

您可以通过添加UITypeEditor来完成此操作.

下面是一个UITypeEditor 示例,它为您提供了用于选择文件名的OpenFileDialog.