-
Notifications
You must be signed in to change notification settings - Fork 0
/
Class1.cs
144 lines (124 loc) · 4.97 KB
/
Class1.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
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
class RoundedButton : Button
{
private int roundRadius = 20;
private float buttonOpacity = 1.0f; // Прозрачность кнопки (от 0 до 1)
private Color buttonBackColor = Color.LightBlue; // Начальный цвет фона
private float borderTickness = 1.75f;
private Color borderColor = Color.CadetBlue;
public int RoundRadius
{
get { return roundRadius; }
set
{
roundRadius = value;
this.Invalidate(); // Перерисовать кнопку при изменении радиуса
}
}
public float ButtonOpacity
{
get { return buttonOpacity; }
set
{
buttonOpacity = Math.Min(1, Math.Max(0, value)); // Ограничиваем значение от 0 до 1
this.Invalidate(); // Перерисовать кнопку при изменении прозрачности
}
}
public Color ButtonBackColor
{
get { return buttonBackColor; }
set
{
buttonBackColor = value;
this.Invalidate(); // Перерисовать кнопку при изменении цвета фона
}
}
public float BorderTickness
{
get { return borderTickness; }
set
{
borderTickness = value;
this.Invalidate();
}
}
public Color BorderColor
{
get { return borderColor; }
set
{
borderColor = value;
this.Invalidate();
}
}
private GraphicsPath GetRoundPath(RectangleF rect, int radius)
{
float r2 = radius / 2f;
GraphicsPath graphPath = new GraphicsPath();
graphPath.AddArc(rect.X, rect.Y, radius, radius, 180, 90);
graphPath.AddLine(rect.X + r2, rect.Y, rect.Width - r2, rect.Y);
graphPath.AddArc(rect.X + rect.Width - radius, rect.Y, radius, radius, 270, 90);
graphPath.AddLine(rect.Width, rect.Y + r2, rect.Width, rect.Height - r2);
graphPath.AddArc(rect.X + rect.Width - radius, rect.Y + rect.Height - radius, radius, radius, 0, 90);
graphPath.AddLine(rect.Width - r2, rect.Height, rect.X + r2, rect.Height);
graphPath.AddArc(rect.X, rect.Y + rect.Height - radius, radius, radius, 90, 90);
graphPath.AddLine(rect.X, rect.Height - r2, rect.X, rect.Y + r2);
graphPath.CloseFigure();
return graphPath;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
RectangleF rect = new RectangleF(0, 0, this.Width, this.Height);
using (GraphicsPath graphPath = GetRoundPath(rect, roundRadius))
{
this.Region = new Region(graphPath);
// Применяем прозрачность к цвету фона
Color transparentButtonBackColor = Color.FromArgb((int)(buttonOpacity * 255), buttonBackColor);
using (Brush brush = new SolidBrush(transparentButtonBackColor))
{
e.Graphics.FillPath(brush, graphPath);
}
if (borderColor != this.BackColor)
using (Pen pen = new Pen(borderColor, borderTickness))
{
pen.Alignment = PenAlignment.Inset;
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.DrawPath(pen, graphPath);
}
}
}
}
class ColoredCheckBox : CheckBox
{
public Color CheckmarkColor { get; set; } = Color.Black; // Цвет галочки
protected override void OnPaint(PaintEventArgs pevent)
{
base.OnPaint(pevent);
// Очищаем текущий фон
pevent.Graphics.Clear(this.BackColor);
// Определяем прямоугольники для галочки и текста
Rectangle checkBoxRect = new Rectangle(0, (this.Height - 16) / 2, 16, 16);
Rectangle textRect = new Rectangle(20, 0, this.Width - 20, this.Height);
// Рисуем фон чекбокса
ControlPaint.DrawCheckBox(pevent.Graphics, checkBoxRect,
this.Checked ? ButtonState.Checked : ButtonState.Normal);
// Рисуем галочку при необходимости
if (this.Checked)
{
using (Pen pen = new Pen(CheckmarkColor, 2))
{
Point start = new Point(checkBoxRect.Left + 3, checkBoxRect.Top + 9);
Point middle = new Point(checkBoxRect.Left + 7, checkBoxRect.Bottom - 4);
Point end = new Point(checkBoxRect.Right - 3, checkBoxRect.Top + 4);
pevent.Graphics.DrawLine(pen, start, middle);
pevent.Graphics.DrawLine(pen, middle, end);
}
}
// Рисуем текст
TextRenderer.DrawText(pevent.Graphics, this.Text, this.Font, textRect, this.ForeColor);
}
}