Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace myNs
- {
- public class FileNameEditor : System.Drawing.Design.UITypeEditor
- {
- private System.Windows.Forms.OpenFileDialog openFileDialog;
- public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
- {
- if (provider != null)
- {
- System.Windows.Forms.Design.IWindowsFormsEditorService windowsFormsEditorService = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));
- if (windowsFormsEditorService != null)
- {
- if (openFileDialog == null)
- {
- openFileDialog = new System.Windows.Forms.OpenFileDialog();
- InitializeDialog(openFileDialog);
- }
- if (value is string)
- {
- openFileDialog.FileName = (string)value;
- }
- if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- value = openFileDialog.FileName;
- }
- }
- }
- return value;
- }
- public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
- {
- return System.Drawing.Design.UITypeEditorEditStyle.Modal;
- }
- protected virtual void InitializeDialog(System.Windows.Forms.OpenFileDialog openFileDialog)
- {
- //openFileDialog.Filter = "GenericFileFilter";
- openFileDialog.Title = "Open File";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement