Advertisement
Guest User

YesNO_Dialogs simplified.

a guest
Jul 26th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1.     // Simply send it a text string to display.
  2.     // False == NO, True == Yes! & default button number 1.
  3.     static public bool YesNoDlg(string text)
  4.     { return YesNoDlg(text, 1); }
  5.     // Overloaded method below...
  6.     static public bool YesNoDlg(string text, int defaultButton)
  7.     // Excellent: ReUse This For ALL such. (GASIT Standard)
  8.     {
  9.       const string msg = "User Input Required";
  10.       bool flag;
  11.       if (defaultButton == 1)
  12.       { // If only string is passed, defaults to this...
  13.         flag = MessageBox.Show(
  14.           text, msg,
  15.           MessageBoxButtons.YesNo,
  16.           MessageBoxIcon.Question,
  17.           MessageBoxDefaultButton.Button1 // YES!
  18.                  ) != DialogResult.No;
  19.       }
  20.       else
  21.       {
  22.         if (defaultButton == 2)
  23.         {
  24.           flag = MessageBox.Show(
  25.             text, msg,
  26.             MessageBoxButtons.YesNo,
  27.             MessageBoxIcon.Question,
  28.             MessageBoxDefaultButton.Button2 // NO!
  29.                    ) != DialogResult.No;
  30.         }
  31.         else
  32.         {
  33.           flag = MessageBox.Show(
  34.             text, msg,
  35.             MessageBoxButtons.YesNo,
  36.             MessageBoxIcon.Question,
  37.             MessageBoxDefaultButton.Button3 // Cancel?
  38.                    ) != DialogResult.No;
  39.         }
  40.       }
  41.       return flag;
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement