public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (context == null || context.Instance == null || provider == null) { return(value); } IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (edSvc == null) { return(value); } using (MemoEditor editor = new MemoEditor()) { Type propType = context.PropertyDescriptor.PropertyType; bool isList = (propType == typeof(List <string>)) || propType.IsSubclassOf(typeof(List <string>)); if (isList) { editor.Caption = "Enter one value per line."; } editor.MemoText = isList ? GetText(value as List <string>) : Utils.NonNullString(value as string); if (edSvc.ShowDialog(editor) == DialogResult.OK) { string text = editor.MemoText; if (text == null) { return(null); } if (isList) { string[] lines = Utils.SplitStringToLines(text); if (lines == null || lines.Length <= 0) { return(null); } List <string> result = //new List<string>(); (List <string>)Activator.CreateInstance(context.PropertyDescriptor.PropertyType); foreach (string str in lines) { if (!string.IsNullOrEmpty(str)) { result.Add(str); } } return(result.Count > 0 ? result : null); } return(text); } } return(value); }
public static void ShowMemo(IWin32Window owner, string caption, string memo) { using var frmMemo = new MemoEditor() { Caption = caption, MemoText = memo }; frmMemo.ShowDialog(owner); }
private void SaveFilesForm_FormClosing(object sender, FormClosingEventArgs e) { if (DialogResult == DialogResult.Cancel) { return; } var listSelectedFiles = new List <SaveFileData>(); foreach (SaveFileData fileData in bindingFiles) { if (fileData.Selected) { listSelectedFiles.Add(fileData); } } if (listSelectedFiles.Count <= 0) { return; } foreach (var fileData in listSelectedFiles) { if (string.IsNullOrWhiteSpace(fileData.FileName) || !Utils.IsFullFileNameValid(Project.Current.MapPath(fileData.FileName))) { XtraMessageBox.Show(this, "One or more of filenames are not valid", "Invalid filename(s)", MessageBoxButtons.OK, MessageBoxIcon.Error); e.Cancel = true; return; } } var errors = new StringBuilder(); foreach (var fileData in listSelectedFiles) { try { fileData.ViewModel.SaveToFile(fileData.FileName); } catch (Exception ex) { errors.AppendLine($"Cannot save file '{fileData.FileName}': {ex.Message}"); } } if (errors.Length > 0) { MemoEditor.ShowMemo(this, "Errors", errors.ToString()); } }