/// <summary> /// See base class docs. /// </summary> /// <param name="context"></param> /// <param name="provider"></param> /// <param name="value"></param> /// <returns></returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { var result = value as string; string folder = result; if (String.IsNullOrEmpty(folder) || !Directory.Exists(folder)) { folder = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); } var folderBrowserAttribute = context.PropertyDescriptor.Attributes.OfType <FolderBrowserAttribute>().FirstOrDefault(); if (folderBrowserAttribute == null) { folderBrowserAttribute = new FolderBrowserAttribute(); } using (var dialog = new FolderBrowserDialog() { Description = String.IsNullOrEmpty(folderBrowserAttribute.Description) ? "" : Localise.GetLocalisedText(folderBrowserAttribute.Description), SelectedPath = folder, ShowNewFolderButton = folderBrowserAttribute.ShowNewFolderButton, }) { if (dialog.ShowDialog() == DialogResult.OK) { result = dialog.SelectedPath; } } return(result); }
/// <summary> /// See base class docs. /// </summary> /// <param name="context"></param> /// <param name="provider"></param> /// <param name="value"></param> /// <returns></returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { var result = value as string; string folder = result; if(String.IsNullOrEmpty(folder) || !Directory.Exists(folder)) folder = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); var folderBrowserAttribute = context.PropertyDescriptor.Attributes.OfType<FolderBrowserAttribute>().FirstOrDefault(); if(folderBrowserAttribute == null) folderBrowserAttribute = new FolderBrowserAttribute(); using(var dialog = new FolderBrowserDialog() { Description = String.IsNullOrEmpty(folderBrowserAttribute.Description) ? "" : Localise.GetLocalisedText(folderBrowserAttribute.Description), SelectedPath = folder, ShowNewFolderButton = folderBrowserAttribute.ShowNewFolderButton, }) { if(dialog.ShowDialog() == DialogResult.OK) result = dialog.SelectedPath; } return result; }