2013-04-14 3 views
0

FolderBrowserDialog를 확장하여 선택한 폴더의 하위 폴더를 포함 할 수있는 옵션을 포함하고자합니다 (포함 여부를 선택하는 확인란 추가). 봉인 된 클래스이므로 기본 FolderBrowserDialog를 확장 할 수 없다는 것을 알았습니다.CommonDialog 클래스에서 파생 된 사용자 정의 사용자 정의 컨트롤을 만드는 방법

그래서 가장 간단한 해결책은 CommonBialserDialog과 동일한 클래스 인 CommonDialog에서 파생 된 사용자 정의 컨트롤을 만드는 것이고 표준 FolderBrowserDialog에서 코드를 복사 한 다음 조금만 변경하여 사용자 정의 컨트롤을 만들 것이라고 생각했습니다. "하위 폴더 포함"확인란.

missing partial modifier on declaration of type [my_class_name] another partial declaration of this type exists c# 

그리고는 "[my_class_name] .Designer.cs"파일에 지적 : 내가 기본에서 코드를 복사 할 때

는하지만 나에게 오류를 제공 FolderBrowserDialog.

namespace my_custom_folder_open 
{ 
    // Summary: 
    //  Prompts the user to select a folder. This class cannot be inherited. 
    [DefaultEvent("HelpRequest")] 
    [DefaultProperty("SelectedPath")] 
    [Designer("System.Windows.Forms.Design.FolderBrowserDialogDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] 
    public sealed class UserControl2 : CommonDialog 
    { 
     // Summary: 
     //  Initializes a new instance of the System.Windows.Forms.FolderBrowserDialog 
     //  class. 
     public UserControl2(); 

     // Summary: 
     //  Gets or sets the descriptive text displayed above the tree view control in 
     //  the dialog box. 
     // 
     // Returns: 
     //  The description to display. The default is an empty string (""). 
     [Browsable(true)] 
     [DefaultValue("")] 
     [Localizable(true)] 
     public string Description { get; set; } 
     // 
     // Summary: 
     //  Gets or sets the root folder where the browsing starts from. 
     // 
     // Returns: 
     //  One of the System.Environment.SpecialFolder values. The default is Desktop. 
     // 
     // Exceptions: 
     // System.ComponentModel.InvalidEnumArgumentException: 
     //  The value assigned is not one of the System.Environment.SpecialFolder values. 
     [Browsable(true)] 
     [Localizable(false)] 
     public Environment.SpecialFolder RootFolder { get; set; } 
     // 
     // Summary: 
     //  Gets or sets the path selected by the user. 
     // 
     // Returns: 
     //  The path of the folder first selected in the dialog box or the last folder 
     //  selected by the user. The default is an empty string (""). 
     [Browsable(true)] 
     [DefaultValue("")] 
     [Localizable(true)] 
     public string SelectedPath { get; set; } 
     // 
     // Summary: 
     //  Gets or sets a value indicating whether the New Folder button appears in 
     //  the folder browser dialog box. 
     // 
     // Returns: 
     //  true if the New Folder button is shown in the dialog box; otherwise, false. 
     //  The default is true. 
     [Browsable(true)] 
     [DefaultValue(true)] 
     [Localizable(false)] 
     public bool ShowNewFolderButton { get; set; } 

     // Summary: 
     //  Occurs when the user clicks the Help button on the dialog box. 
     [Browsable(false)] 
     [EditorBrowsable(EditorBrowsableState.Never)] 
     public event EventHandler HelpRequest; 

     // Summary: 
     //  Resets properties to their default values. 
     public override void Reset(); 
     protected override bool RunDialog(IntPtr hWndOwner); 
    } 
} 

어디에서 문제가 될 수 있습니까?

는 Btw은 내가 당신이 가진 잘못된 궤도에 심각 있습니다 윈도우 컨트롤 라이브러리 양식으로 프로젝트 ..

+0

제목을 편집했습니다. "[제목에"태그 "가 포함되어 있어야합니까?] (http://meta.stackexchange.com/questions/19190/)"합의가 "아니오, 그렇지 않아야한다"는 것을 참조하십시오. –

답변

2

을 만들었습니다. 이러한 대화 상자는 컨트롤이 아닌 구성 요소입니다. 그것들은 Windows에 내장 된 대화 상자 주위의 매우 얇은 래퍼입니다. 이러한 대화 상자 자체는 .NET에 대해 아무것도 모르고 비 관리 코드로 작성됩니다. 컴포넌트가 아니라 일반 클래스가 아닌 유일한 이유는 폼에 하나를 놓을 수있게하는 것입니다. 디자이너에게 몇 가지 속성을 설정하는 데 유용합니다.

"CommonDialog"라는 용어는 오해의 소지가 있었을 수도 있습니다. Microsoft는 GUI 프로그램에서 일반적으로 사용되는 대화 상자이기 때문에이를 "공통"이라고했습니다. 그리고 내장 된 프로그램을 사용하도록 권장하여 모든 프로그램이 파일을 여는 것과 매우 유사한 방식으로 작동하도록했습니다.

사용자 지정 대화 상자를 만들 필요가 없기 때문에 CommonDialog에서 파생되는 것이 중요하지 않습니다. Windows에는 기본 제공 클래스 만 있고 이미 각각의 .NET 클래스로 래핑되어 있기 때문입니다. 당신의 계획은 네이티브 FolderBrowserDialog가 할 수있는 것을 망칠 것입니다. 체크 박스 표시가 포함되지 않습니다. 정당한 이유로 봉인되었습니다.

0

CommonDialog에서 새 클래스를 파생 시켜서 문제를 해결할 수 없다는 Hans가 정확합니다. 하지만 폴더 픽커 모드에서 IFileDialog 구성 요소를 사용하면됩니다. 확인란을 추가하려면 IFileDialogCustomize을 사용해야합니다. 이것은 COM이므로 실제로 .net에서 사용하는 것은 매우 간단합니다.