簡體   English   中英

如何在自定義控件的屬性網格中獲取OpenFileDialog?

[英]How can I get an OpenFileDialog in a custom control's property grid?

我正在創建.net自定義控件,它應該能夠加載多個文本文件。 我有一個名為ListFiles的公共屬性,其中包含以下屬性:


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

根據對象的類型(string,string [],List,...),屬性網格將允許用戶輸入一些數據。我的目標是在我的組件的屬性網格中有一個過濾的openfiledialog這將使用戶能夠選擇多個文件並將其作為數組或字符串(或其他東西......)返回。

Sooo ...這是我的問題: 如何在自定義控件的屬性網格中獲得OpenFileDialog?

非常感謝!

您可以使用內置的UITypeEditor。 它被稱為FileNameEditor

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

public string SomeFilePath
{
 get;
 set;
}

您可以通過添加UITypeEditor來完成此操作。

下面是一個UITypeEditor 示例 ,它為您提供了用於選擇文件名的OpenFileDialog。

這是自定義文件對話框的另一個示例:

CustomFileEditor.cs

using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace YourNameSpace
{
    class CustomFileBrowser : FileNameEditor
    {
        protected override void InitializeDialog(OpenFileDialog openFileDialog)
        {
            base.InitializeDialog(openFileDialog);
            openFileDialog.Title = "Select Project File : ";
            openFileDialog.Filter = "Project File (*.proj)|*.proj"; ;
        }
    }

}

用法:

            [Category("Settings"), DisplayName("Project File:")]
            [EditorAttribute(typeof(CustomFileBrowser), typeof(System.Drawing.Design.UITypeEditor))]
            public string Project_File { get; set; }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM