Example #1
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (context != null && editorService != null)
            {
                using (var dialog = CreateFileDialog())
                {
                    var fileName = value as string;
                    if (!string.IsNullOrEmpty(fileName))
                    {
                        dialog.FileName = fileName;
                    }

                    var filterAttribute = (FileNameFilterAttribute)context.PropertyDescriptor.Attributes[typeof(FileNameFilterAttribute)];
                    var filter          = filterAttribute != null ? filterAttribute.Filter : "All Files|*.*";
                    dialog.Filter = filter;

                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        return(PathConvert.GetProjectPath(dialog.FileName));
                    }
                }
            }

            return(base.EditValue(context, provider, value));
        }
Example #2
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (context != null && editorService != null)
            {
                using (var dialog = new FolderBrowserDialog())
                {
                    var folderName = value as string;
                    if (!string.IsNullOrEmpty(folderName))
                    {
                        dialog.SelectedPath = Path.GetFullPath(folderName);
                    }
                    else
                    {
                        dialog.SelectedPath = Environment.CurrentDirectory;
                    }

                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        return(PathConvert.GetProjectPath(dialog.SelectedPath));
                    }
                }
            }

            return(base.EditValue(context, provider, value));
        }