public class FileEditor : UITypeEditor {
private OpenFileDialog openFileDialog;
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) {
if (openFileDialog == null){
openFileDialog = new OpenFileDialog();
}
openFileDialog.DefaultExt = "dat";
openFileDialog.Multiselect = false;
openFileDialog.Title = "Select Attachment";
openFileDialog.CheckFileExists = true;
openFileDialog.CheckPathExists = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
return new FileName(openFileDialog.FileName);
return null;
}
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) {
return UITypeEditorEditStyle.Modal;
}
}
|