forked from JDDKCN/SMSBoomGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ErrorForm.cs
160 lines (137 loc) · 5.16 KB
/
ErrorForm.cs
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SMSBoomGUI
{
public partial class ErrorForm : Form
{
public ErrorForm()
{
InitializeComponent();
}
#region 绘制圆角窗体
private void SetWindowRegion()
{
GraphicsPath path = new GraphicsPath();
Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);
path = getRoundRectPath(rect, 50);
this.Region = new Region(path);
}
private GraphicsPath getRoundRectPath(Rectangle rect, int radius)
{
GraphicsPath path = new GraphicsPath();
Rectangle arcRect = new Rectangle(rect.Location, new Size(radius, radius));
//左上角
path.AddArc(arcRect, 180, 90);//从180度开始,顺时针,滑过90度
//右上角
arcRect.X = rect.Right - radius;
path.AddArc(arcRect, 270, 90); //
//右下角
arcRect.Y = rect.Bottom - radius;
path.AddArc(arcRect, 0, 90);
//左下角
arcRect.X = rect.Left;
path.AddArc(arcRect, 90, 90);
path.CloseFigure();//闭合曲线
return path;
}
private void ErrorForm_Resize(object sender, EventArgs e)
{
SetWindowRegion();
}
#endregion
#region 绘制程序Panel
private void panel1_Paint(object sender, PaintEventArgs e)
{
panel1.BackColor = Color.FromArgb(150, 131, 175, 200);//ARGB,第一个为调节不透明度
ControlPaint.DrawBorder(e.Graphics,
panel1.ClientRectangle,
Color.White,
1,
ButtonBorderStyle.Solid,
Color.White,
1,
ButtonBorderStyle.Solid,
Color.White,
1,
ButtonBorderStyle.Solid,
Color.White,
1,
ButtonBorderStyle.Solid);
}
#endregion
#region 鼠标事件
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
bool beginMove = false;//初始化鼠标位置
int currentXPosition;
int currentYPosition;
private void panel1_MouseDown_1(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
beginMove = true;
currentXPosition = MousePosition.X;//鼠标的x坐标为当前窗体左上角x坐标
currentYPosition = MousePosition.Y;//鼠标的y坐标为当前窗体左上角y坐标
}
}
private void panel1_MouseMove_1(object sender, MouseEventArgs e)
{
if (beginMove)
{
this.Left += MousePosition.X - currentXPosition;//根据鼠标x坐标确定窗体的左边坐标x
this.Top += MousePosition.Y - currentYPosition;//根据鼠标的y坐标窗体的顶部,即Y坐标
currentXPosition = MousePosition.X;
currentYPosition = MousePosition.Y;
}
}
private void panel1_MouseUp_1(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
currentXPosition = 0; //设置初始状态
currentYPosition = 0;
beginMove = false;
}
}
private void pictureBox1_MouseEnter(object sender, EventArgs e)
{
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
pictureBox1.BackColor = Color.Red;
}
private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
pictureBox1.BackColor = Color.Transparent;
}
#endregion
private void ErrorForm_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
private void btn_cancle_Click_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
Close();
}
}
}