사용자 정의 컨트롤의 속성 그리드에서 OpenFileDialog를 어떻게 얻을 수 있습니까?
-
05-07-2019 - |
문제
.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를 어떻게 얻을 수 있습니까?
정말 감사합니다!
해결책
a를 추가하여이를 수행 할 수 있습니다 uitypeeditor.
여기 예입니다 파일 이름을 수집하기위한 OpenFiledialog를 제공하는 uitypeeditor의.
다른 팁
내장 UityPeeditor를 사용할 수 있습니다. 그것은이라고 filenameeditor
[EditorAttribute(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
public string SomeFilePath
{
get;
set;
}
다음은 파일 사용자 정의 대화 상자와 함께 제공됩니다.
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; }
제휴하지 않습니다 StackOverflow