2012-10-20 1 views
0

사용자 지정 FileNameEditor를 구현하려고합니다. 내 필터를 설정하고 여러 파일을 선택할 수 있기를 원합니다.사용자 지정 FileNameEditor

public class Settings 
{ 
    [EditorAttribute(typeof(FileNamesEditor), typeof(System.Drawing.Design.UITypeEditor))] 
    public string FileNames { get; set; } 
} 

public class FileNamesEditor : FileNameEditor 
{ 
    protected override void InitializeDialog(OpenFileDialog openFileDialog) 
    { 
     openFileDialog.Multiselect = true; 
     openFileDialog.Filter = "Word|*.docx|All|*.*"; 
     base.InitializeDialog(openFileDialog); 

    } 
} 

이 필터 속성을 무시하고 내가 내 Settings.FileNames 속성에 할당 할 수없는 여러 개의 파일을 선택할 수 있어요하지만 Settings.FileNames 유형 문자열 []와 파생 클래스의 결과이기 때문에 문자열입니다. 파생 클래스에서 openFileDialog의 FileNames를 반환하고 필터를 작동시키는 방법은 무엇입니까? 내가 뭘 놓치고 있니? 그것이 어떻게 작동하는지

+0

난 정말 당신의 질문을 이해하지 않습니다 (디버깅 멋지게 표시됩니다), 대화 상자는 속성을 파일 이름을 불렀다 foreach. 나는 Settings 클래스도 붕괴시키지 않는다. FileNames 속성에는 무엇이 있어야합니까? 파일을 쉼표로 구분하고 싶습니까? – rfcdejong

+0

설정 클래스는 계산할 입력 파일, 도우미 어셈블리에 대한 경로, 출력 형식 옵션, 전역 화 설정 및 기타와 같은 몇 가지 설정을 포함합니다 ... 설정을 저장할 때 일련 화되고 각 programm 시작시로드되어 사용자가 선택을 저장하지 못하도록합니다 응용 프로그램을 시작할 때마다 입력 파일은 OpenFileDialog를 사용하여 선택 가능해야합니다 ... 설정은 propertygrid에 표시된 일반 클래스입니다. – Llarian

답변

0

는 아마도 문자열 []

public class Settings 
{ 
    [EditorAttribute(typeof(System.ComponentModel.Design.ArrayEditor), typeof(System.Drawing.Design.UITypeEditor))] 
    public string[] FileNames { get ; set; } 
} 
+0

FileNameEditor를 UITypeEditor로 사용하고 싶지만 설정을 적용해야합니다. – Llarian

+0

http://winterdom.com/2006/08/acustomuitypeeditorforactivityproperties – rfcdejong

0

자에 대한 ArrayEditor를 사용,이

public class FileNamesEditor : UITypeEditor 
{ 
    private OpenFileDialog ofd; 
    public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) 
    { 
     return UITypeEditorEditStyle.Modal; 
    } 
    public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) 
    { 
     if ((context != null) && (provider != null)) 
     { 
      IWindowsFormsEditorService editorService = 
      (IWindowsFormsEditorService) 
      provider.GetService(typeof(IWindowsFormsEditorService)); 
      if (editorService != null) 
      { 
       ofd = new OpenFileDialog(); 
       ofd.Multiselect = true; 
       ofd.Filter = "Word|*.docx|All|*.*"; 
       ofd.FileName = ""; 
       if (ofd.ShowDialog() == DialogResult.OK) 
       { 
        return ofd.FileNames; 
       } 
      } 
     } 
     return base.EditValue(context, provider, value); 
    } 
} 
+0

정답을보고 [편집자 (typeof (FileNamesEditor), typeof (UITypeEditor))]와 함께 사용하십시오) – rfcdejong

3

원래 코드가 필요한 재를 제외하고, 나를 위해 일한입니다 ... 주문. 당신이 할 수있는 당신은 변경 전에 base.Initialize를 호출해야하거나 덮어 얻을

public class FileNamesEditor : FileNameEditor 
{ 
    protected override void InitializeDialog(OpenFileDialog openFileDialog) 
    { 
     base.InitializeDialog(openFileDialog); 
     openFileDialog.Multiselect = true; 
     openFileDialog.Filter = "Word|*.docx|All|*.*"; 
    } 
} 
관련 문제