SHOW:
|
|
- or go back to the newest paste.
1 | using System; | |
2 | using System.Drawing; | |
3 | using System.Windows.Forms; | |
4 | ||
5 | public static class CustomMessageBox | |
6 | { | |
7 | public static DialogResult Show(string Text, string Title, eDialogButtons Buttons, Image Image) | |
8 | { | |
9 | MessageForm message = new MessageForm(); | |
10 | message.Text = Title; | |
11 | ||
12 | if (Image.Height < 0 || Image.Height > 64) | |
13 | throw new Exception("Invalid image height. Valid height ranges from 0 to 64."); | |
14 | else if (Image.Width < 0 || Image.Width > 64) | |
15 | throw new Exception("Invalid image width. Valid width ranges from 0 to 64."); | |
16 | else | |
17 | { | |
18 | ||
19 | message.picImage.Image = Image; | |
20 | message.lblText.Text = Text; | |
21 | ||
22 | switch (Buttons) | |
23 | { | |
24 | case eDialogButtons.OK: | |
25 | message.btnYes.Visible = false; | |
26 | message.btnNo.Visible = false; | |
27 | message.btnCancel.Visible = false; | |
28 | message.btnOK.Location = message.btnCancel.Location; | |
29 | break; | |
30 | case eDialogButtons.OKCancel: | |
31 | message.btnYes.Visible = false; | |
32 | message.btnNo.Visible = false; | |
33 | break; | |
34 | case eDialogButtons.YesNo: | |
35 | message.btnOK.Visible = false; | |
36 | message.btnCancel.Visible = false; | |
37 | message.btnYes.Location = message.btnOK.Location; | |
38 | message.btnNo.Location = message.btnCancel.Location; | |
39 | break; | |
40 | case eDialogButtons.YesNoCancel: | |
41 | message.btnOK.Visible = false; | |
42 | break; | |
43 | } | |
44 | ||
45 | if (message.lblText.Height > 64) | |
46 | message.Height = (message.lblText.Top + message.lblText.Height) + 78; | |
47 | ||
48 | return (message.ShowDialog()); | |
49 | } | |
50 | } | |
51 | ||
52 | public enum eDialogButtons | |
53 | { | |
54 | OK, | |
55 | OKCancel, | |
56 | YesNo, | |
57 | YesNoCancel | |
58 | } | |
59 | } |