Advertisement
retesere20

fileditor-select-browse-dialog

Jul 10th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. namespace myNs
  2. {
  3. public class FileNameEditor : System.Drawing.Design.UITypeEditor
  4. {
  5. private System.Windows.Forms.OpenFileDialog openFileDialog;
  6.  
  7. public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
  8. {
  9. if (provider != null)
  10. {
  11. System.Windows.Forms.Design.IWindowsFormsEditorService windowsFormsEditorService = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));
  12. if (windowsFormsEditorService != null)
  13. {
  14. if (openFileDialog == null)
  15. {
  16. openFileDialog = new System.Windows.Forms.OpenFileDialog();
  17. InitializeDialog(openFileDialog);
  18. }
  19. if (value is string)
  20. {
  21. openFileDialog.FileName = (string)value;
  22. }
  23. if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  24. {
  25. value = openFileDialog.FileName;
  26. }
  27. }
  28. }
  29. return value;
  30. }
  31.  
  32. public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
  33. {
  34. return System.Drawing.Design.UITypeEditorEditStyle.Modal;
  35. }
  36.  
  37. protected virtual void InitializeDialog(System.Windows.Forms.OpenFileDialog openFileDialog)
  38. {
  39. //openFileDialog.Filter = "GenericFileFilter";
  40. openFileDialog.Title = "Open File";
  41. }
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement