SurMessage.cs
4.2 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Asa.Face
{
public partial class SurMessage : SurForm
{
private MessageBoxButtons _buttons = MessageBoxButtons.OKCancel;
private DialogResult[] _result = new DialogResult[3];
private const int MIN_W = 350;
private const int MIN_H = 190;
private readonly int MAX_W;
private readonly int MAX_H;
private readonly int tempX;
private readonly int tempY;
public SurMessage()
{
InitializeComponent();
MAX_W = Screen.FromControl(this).WorkingArea.Width / 2;
MAX_H = Screen.FromControl(this).WorkingArea.Height / 2;
tempX = Width - surLabel1.Width;
tempY = Height - surLabel1.Height;
}
/// <summary>
/// 对话框
/// </summary>
/// <param name="title">标题</param>
/// <param name="content">内容</param>
/// <param name="buttons">按钮</param>
public SurMessage(string title, string content, MessageBoxButtons buttons) : this()
{
Text = title;
surLabel1.Text = content;
_buttons = buttons;
Graphics g = CreateGraphics();
SizeF sf = g.MeasureString(content, surLabel1.Font, MAX_W);
if (sf.Width < MIN_W)
Width = MIN_W + tempX;
else
Width = Convert.ToInt32(sf.Width) + tempX;
if (sf.Height > MAX_H)
Height = MAX_H + tempY;
else if (sf.Height < MIN_H)
Height = MIN_H + tempY;
else
Height = Convert.ToInt32(sf.Height) + tempY;
}
private void SurMessage_Load(object sender, EventArgs e)
{
switch (_buttons)
{
case MessageBoxButtons.OK:
surButton1.Visible = false;
surButton2.Visible = false;
surButton3.Text = "OK";
_result[2] = DialogResult.OK;
break;
case MessageBoxButtons.OKCancel:
surButton1.Visible = false;
surButton2.Text = "OK";
surButton3.Text = "Cancel";
_result[1] = DialogResult.OK;
_result[2] = DialogResult.Cancel;
break;
case MessageBoxButtons.AbortRetryIgnore:
surButton1.Text = "Abort";
surButton2.Text = "Retry";
surButton3.Text = "Ignore";
_result[0] = DialogResult.Abort;
_result[1] = DialogResult.Retry;
_result[2] = DialogResult.Ignore;
break;
case MessageBoxButtons.YesNoCancel:
surButton1.Text = "Yes";
surButton2.Text = "No";
surButton3.Text = "Cancel";
_result[0] = DialogResult.Yes;
_result[1] = DialogResult.No;
_result[2] = DialogResult.Cancel;
break;
case MessageBoxButtons.YesNo:
surButton1.Visible = false;
surButton2.Text = "Yes";
surButton3.Text = "No";
_result[1] = DialogResult.Yes;
_result[2] = DialogResult.No;
break;
case MessageBoxButtons.RetryCancel:
surButton1.Visible = false;
surButton2.Text = "Retry";
surButton3.Text = "Cancel";
_result[1] = DialogResult.Retry;
_result[2] = DialogResult.Cancel;
break;
}
}
private void SurButton1_Click(object sender)
{
DialogResult = _result[0];
}
private void SurButton2_Click(object sender)
{
DialogResult = _result[1];
}
private void SurButton3_Click(object sender)
{
DialogResult = _result[2];
}
}
}