FaceMessageBox.cs
3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Asa.FaceControl
{
public partial class FaceMessageBox : FormBase
{
private readonly Dictionary<MessageBoxButtons, Action> msgButton;
private readonly DialogResult[] dialog;
private readonly FaceButton[] button;
public FaceMessageBox(string title, string text, MessageBoxButtons button)
{
InitializeComponent();
ctlClose.Click += CtlClose_Click;
CanResize = false;
dialog = new DialogResult[3];
this.button = new FaceButton[3] { BtnOne, BtnTwo, BtnThree };
BtnOne.Click += BtnMessage_Click;
BtnTwo.Click += BtnMessage_Click;
BtnThree.Click += BtnMessage_Click;
msgButton = new Dictionary<MessageBoxButtons, Action>
{
{ MessageBoxButtons.OK, MsgOK },
{ MessageBoxButtons.OKCancel, MsgOKCancel },
{ MessageBoxButtons.AbortRetryIgnore, MsgAbortRetryIgnore },
{ MessageBoxButtons.YesNoCancel, MsgYesNoCancel },
{ MessageBoxButtons.YesNo, MsgYesNo },
{ MessageBoxButtons.RetryCancel, MsgRetryCancel }
};
Text = title;
faceLabel1.Text = text;
msgButton[button].Invoke();
}
protected override void CalcSize()
{
base.CalcSize();
int n = 1;
if (ctlClose != null)
{
ctlClose.Size = new Size(60, TitleHeight - 5);
n += ctlClose.Width;
ctlClose.Location = new Point(Width - BorderWidth - n, BorderWidth + 1);
ctlClose.Anchor = AnchorStyles.Top | AnchorStyles.Right;
}
}
private void MsgOK()
{
button[2].Text = "OK";
dialog[2] = DialogResult.OK;
button[0].Visible = button[1].Visible = false;
}
private void MsgOKCancel()
{
button[1].Text = "OK";
dialog[1] = DialogResult.OK;
button[2].Text = "Cancel";
dialog[2] = DialogResult.Cancel;
button[0].Visible = false;
}
private void MsgAbortRetryIgnore()
{
button[0].Text = "Abort";
dialog[0] = DialogResult.Abort;
button[1].Text = "Retry";
dialog[1] = DialogResult.Retry;
button[2].Text = "Ignore";
dialog[2] = DialogResult.Ignore;
}
private void MsgYesNoCancel()
{
button[0].Text = "Yes";
dialog[0] = DialogResult.Yes;
button[1].Text = "No";
dialog[1] = DialogResult.No;
button[2].Text = "Cancel";
dialog[2] = DialogResult.Cancel;
}
private void MsgYesNo()
{
button[1].Text = "Yes";
dialog[1] = DialogResult.Yes;
button[2].Text = "No";
dialog[2] = DialogResult.No;
button[0].Visible = false;
}
private void MsgRetryCancel()
{
button[1].Text = "Retry";
dialog[1] = DialogResult.Retry;
button[2].Text = "Cancel";
dialog[2] = DialogResult.Cancel;
button[0].Visible = false;
}
private void CtlClose_Click(object sender, EventArgs e)
{
Close();
}
private void BtnMessage_Click(object sender, EventArgs e)
{
FaceButton btn = sender as FaceButton;
int index = Array.FindIndex(button, s => s == btn);
if (index == -1) return;
DialogResult = dialog[index];
}
}
}