FaceLoading.cs
2.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
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.FaceControl
{
public partial class FaceLoading : ControlBase
{
private bool loop = false;
private int circleIndex = -1;
private readonly int circleCount = 12;
private readonly int circleRadius = 10;
private List<RectangleF> circleCenter;
public FaceLoading()
{
InitializeComponent();
circleCenter = new();
}
public void Start()
{
loop = true;
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(Run));
thread.Start();
}
public void Stop()
{
loop = false;
circleIndex = -1;
Refresh();
}
protected override void CalcSize()
{
base.CalcSize();
PointF center = new(Width / 2f, Height / 2f);
float radius = Math.Min(center.X * 2f / 3f, center.Y * 2f / 3f);
circleCenter = new();
for (int i = 0; i < circleCount; i++)
{
double angle = 360d / circleCount * i;
angle = Math.PI * angle / 180;
float x = Convert.ToSingle(center.X + Math.Sin(angle) * radius);
float y = Convert.ToSingle(center.Y - Math.Cos(angle) * radius);
circleCenter.Add(new RectangleF(x - circleRadius, y - circleRadius, circleRadius * 2, circleRadius * 2));
}
}
protected override void DrawEnabled(Graphics g)
{
base.DrawEnabled(g);
for (int i = 0; i < circleCenter.Count; i++)
{
if (i == circleIndex)
g.FillEllipse(new SolidBrush(theme.DOWN), circleCenter[i]);
else
g.FillEllipse(new SolidBrush(theme.FORE), circleCenter[i]);
}
}
protected override void DrawDisabled(Graphics g)
{
base.DrawDisabled(g);
}
private void Run()
{
circleIndex = 0;
try
{
while (loop)
{
Invoke(new Action(() => { Refresh(); }));
System.Threading.Thread.Sleep(100);
circleIndex++;
if (circleIndex == circleCount) circleIndex = 0;
}
}
catch (Exception ex)
{
}
}
}
}