// System Icons example: Bitmap.FromHicon(SystemIcons.Exclamation.Handle) // Resource PNG Icons/Images example: Properties.Resources.LedGuitar // // Sample Usage: // result = BetterDialog2.ShowDialog(null, "Dialog Title", "Button1Text", "Button2Text", "Button3Text", Properties.Resources.IconImage or Bitmap.FromHicon(SystemIcons.Information.Handle), "IconMessage", 150, 150); // if (BetterDialog2.ShowDialog(null, "Dialog Title", "Button1Text", "Button2Text", "Button3Text", Properties.Resources.IconImage or Bitmap.FromHicon(SystemIcons.Information.Handle), "IconMessage", 150, 150) == DialogResult.No) // /// <summary> /// Custom Dialog Box to replace standard Message Box with positioning /// </summary> /// <param name="dialogTitle">Title displayed in dialog frame at top</param> /// <param name="dialogIcon">Image displayed left side</param> /// <param name="iconMessage">Promenent bold message displayed to right of icon</param> /// <param name="dialogMessage">Main dialog message, if 'null' then not displayed</param> /// <param name="textDialogButton1">Message box 1 button text, if 'null' then not displayed</param> /// <param name="textDialogButton2">Message box 2 button text, if 'null' then not displayed</param> /// <param name="textDialogButton3">Message box 3 button text, if 'null' then not displayed</param> /// <param name="topFromCenter">Positive pixel distance up from screen center, default location is centered on screen</param> /// <param name="leftFromCenter">Positive pixel distance left from screen center, default location is centered on screen</param> public static DialogResult ShowDialog(string dialogMessage, string dialogTitle, string textDialogButton1, string textDialogButton2, string textDialogButton3, Image dialogIcon, string iconMessage, int topFromCenter = 0, int leftFromCenter = 0) { using (BetterDialog2 dialog = new BetterDialog2(dialogMessage, dialogTitle, textDialogButton1, textDialogButton2, textDialogButton3, dialogIcon, iconMessage, topFromCenter, leftFromCenter)) { DialogResult result = dialog.ShowDialog(); return(result); } }
public static bool PromptOverwrite(string destPath) { if (File.Exists(destPath)) { if (BetterDialog2.ShowDialog(Path.GetFileName(destPath) + @" already exists." + Environment.NewLine + Environment.NewLine + @"Overwrite the existing file?", @"Warning: Overwrite File Message", null, "Yes", "No", Bitmap.FromHicon(SystemIcons.Warning.Handle), "Warning ...", 150, 150) == DialogResult.No) { return(false); } } return(true); }
public static bool MakeDirectory(string dirPath) { try { Directory.CreateDirectory(dirPath); return(true); } catch (IOException e) { BetterDialog2.ShowDialog( "Could not create the directory structure. Error Code: " + e.Message, MESSAGEBOX_CAPTION, null, null, "OK", Bitmap.FromHicon(SystemIcons.Warning.Handle), "Warning ...", 150, 150); return(false); } }
private void TreeViewOfd_Load(object sender, EventArgs e) { PopulateComboFilesOfType(); // call InitBrowserTreeview ONLY after the form is fully loaded var errMsg = treeViewBrowser.InitTreeViewBrowser(); if (!String.IsNullOrEmpty(errMsg)) { var diaMsg = "Your OS Customizations have prevented the" + Environment.NewLine + "TreeViewOfd feature from functioning normally ..." + Environment.NewLine + Environment.NewLine + StringExtensions.SplitString(errMsg, 48, true); BetterDialog2.ShowDialog(diaMsg, "TreeViewOfd Failed ...", null, null, "OK", Bitmap.FromHicon(SystemIcons.Warning.Handle), "Warning", 150, 150); this.DialogResult = DialogResult.Abort; this.Close(); } }
public static bool CopyFile(string fileFrom, string fileTo, bool overWrite, bool verbose = true) { if (verbose) { if (!PromptOverwrite(fileTo)) { return(false); } else { overWrite = true; } } var fileToDir = Path.GetDirectoryName(fileTo); if (!Directory.Exists(fileToDir)) { MakeDirectory(fileToDir); } try { File.SetAttributes(fileFrom, FileAttributes.Normal); File.Copy(fileFrom, fileTo, overWrite); return(true); } catch (IOException e) { if (!overWrite) { return(true); // be nice don't throw error } BetterDialog2.ShowDialog( "Could not copy file " + fileFrom + "\r\nError Code: " + e.Message + "\r\nMake sure associated file/folders are closed.", MESSAGEBOX_CAPTION, null, null, "OK", Bitmap.FromHicon(SystemIcons.Warning.Handle), "Warning ...", 150, 150); return(false); } }
public static bool MoveFile(string fileFrom, string fileTo, bool verbose = true) { if (File.Exists(fileTo)) { if (!verbose) { File.Delete(fileTo); } else if (!PromptOverwrite(fileTo)) { return(false); } else { File.Delete(fileTo); } } else { var fileToDir = Path.GetDirectoryName(fileTo); if (!Directory.Exists(fileToDir)) { MakeDirectory(fileToDir); } } try { File.Copy(fileFrom, fileTo); DeleteFile(fileFrom); return(true); } catch (IOException e) { BetterDialog2.ShowDialog( "Could not move the file " + fileFrom + " Error Code: " + e.Message, MESSAGEBOX_CAPTION, null, null, "OK", Bitmap.FromHicon(SystemIcons.Warning.Handle), "Warning ...", 150, 150); return(false); } }
// System Icons example: Bitmap.FromHicon(SystemIcons.Exclamation.Handle) // Resource PNG Icons/Images example: Properties.Resources.LedGuitar // // Sample Usage: // result = BetterDialog2.ShowDialog(null, "Dialog Title", "Button1Text", "Button2Text", "Button3Text", Properties.Resources.IconImage or Bitmap.FromHicon(SystemIcons.Information.Handle), "IconMessage", 150, 150); // if (BetterDialog2.ShowDialog(null, "Dialog Title", "Button1Text", "Button2Text", "Button3Text", Properties.Resources.IconImage or Bitmap.FromHicon(SystemIcons.Information.Handle), "IconMessage", 150, 150) == DialogResult.No) // /// <summary> /// Custom Dialog Box to replace standard Message Box with positioning /// </summary> /// <param name="dialogTitle">Title displayed in dialog frame at top</param> /// <param name="dialogIcon">Image displayed left side</param> /// <param name="iconMessage">Promenent bold message displayed to right of icon</param> /// <param name="dialogMessage">Main dialog message, if 'null' then not displayed</param> /// <param name="textDialogButton1">Message box 1 button text, if 'null' then not displayed</param> /// <param name="textDialogButton2">Message box 2 button text, if 'null' then not displayed</param> /// <param name="textDialogButton3">Message box 3 button text, if 'null' then not displayed</param> /// <param name="topFromCenter">Positive pixel distance up from screen center, default location is centered on screen</param> /// <param name="leftFromCenter">Positive pixel distance left from screen center, default location is centered on screen</param> public static DialogResult ShowDialog(string dialogMessage, string dialogTitle, string textDialogButton1, string textDialogButton2, string textDialogButton3, Image dialogIcon, string iconMessage, int topFromCenter = 0, int leftFromCenter = 0) { using (BetterDialog2 dialog = new BetterDialog2(dialogMessage, dialogTitle, textDialogButton1, textDialogButton2, textDialogButton3, dialogIcon, iconMessage, topFromCenter, leftFromCenter)) { DialogResult result = dialog.ShowDialog(); return result; } }