我想扩展 FolderBrowserDialog 以选择包含所选文件夹的子文件夹(添加复选框以设置是否包含)。我发现我无法扩展基本的 FolderBrowserDialog,因为它是一个密封类。
所以我认为最简单的解决方案是创建一个用户控件,它派生自 CommonDialog(与 FolderBrowserDialog 相同的类),从标准 FolderBrowserDialog 复制代码并稍微改变它,使其也具有“包含子文件夹" 复选框。
但是当我从默认的 FolderBrowserDialog 复制代码时,它给了我一个错误:
missing partial modifier on declaration of type [my_class_name] another partial declaration of this type exists c#
它指出了“[my_class_name].Designer.cs”文件。
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);
}
}
哪里可能有问题?
顺便说一句,我已经将该项目创建为 Windows 窗体控件库..