-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetroToggleButton.cs
More file actions
87 lines (65 loc) · 2.52 KB
/
Copy pathMetroToggleButton.cs
File metadata and controls
87 lines (65 loc) · 2.52 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Windows.Forms;
namespace GDI_BillenőGomb
{
class MetroButton : Button
{
Color ledColor;
bool checkedState;
public Color LedColor
{
get => ledColor;
set
{
ledColor = value;
Invalidate();
}
}
public bool CheckedState
{
get => checkedState;
set
{
checkedState = value;
Invalidate();
}
}
public MetroButton() : base()
{
LedColor = Color.Blue;
//SolidBrush blackBrush = new SolidBrush(Color.Black);
checkedState = false;
MinimumSize = new Size(90, 50);
}
protected override void OnPaint(PaintEventArgs pevent)
{
//base.OnPaint(pevent);
Graphics gr = pevent.Graphics;
gr.Clear(BackColor);
//gr.DrawRectangle(new Pen(ForeColor),0,0,Width-1,Height-1);
SizeF szovegmerete = gr.MeasureString(Text, Font);
//gr.DrawString(Text, Font, new Pen(ForeColor).Brush,Width/2 - szovegmerete.Width/2,Height/3-szovegmerete.Height/2);
Size ledsize = new Size(Width/2 , Height/3 );
if (CheckedState)
{
gr.FillRectangle(new Pen(LedColor).Brush, Width/2- ledsize.Width/2, Height/3+szovegmerete.Height/2 +5,ledsize.Width, ledsize.Height );
//Újrafestjük a bal oldalit
gr.FillRectangle(new SolidBrush(Color.Blue), Width / 2 - ledsize.Width / 2, Height / 3 + szovegmerete.Height / 2 + 5, 10, ledsize.Height);
//rajzoljuk a jobb oldalit
gr.FillRectangle(new SolidBrush(Color.Black), Width / 2 - ledsize.Width / 2 + ledsize.Width - 10, Height / 3 + szovegmerete.Height / 2 + 5, 10, ledsize.Height);
}
gr.DrawRectangle(new Pen(ForeColor), Width / 2 - ledsize.Width / 2, Height / 3 + szovegmerete.Height / 2 + 5, ledsize.Width, ledsize.Height);
gr.FillRectangle(new SolidBrush(Color.Black), Width / 2 - ledsize.Width / 2, Height / 3 + szovegmerete.Height / 2 + 5, 10, ledsize.Height);
}
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
CheckedState = !CheckedState;
}
}
}