-
Notifications
You must be signed in to change notification settings - Fork 8
/
Utility.cs
116 lines (95 loc) · 3.21 KB
/
Utility.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
#region License
/* Copyright (c) 2017 Fabrice Lacharme
* This code was originally written by Jigar Desai
* http://www.c-sharpcorner.com/article/knob-control-using-windows-forms-and-gdi/
* Note that another implementation exists in vb.net by Blong
* https://www.codeproject.com/Articles/2563/VB-NET-Knob-Control-using-Windows-Forms-and-GDI?msg=1884770#xx1884770xx
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#endregion
#region Contact
/*
* Fabrice Lacharme
* Email: [email protected]
*/
#endregion
using System;
using System.Drawing;
namespace KnobControl
{
/// <summary>
/// Summary description for Utility.
/// </summary>
public class Utility
{
public static float GetRadian(float val)
{
return (float)(val * Math.PI / 180);
}
public static Color GetDarkColor(Color c,byte d)
{
byte r = 0 ;
byte g = 0;
byte b = 0 ;
if (c.R > d) r = (byte)(c.R - d);
if (c.G > d) g = (byte)(c.G - d);
if (c.B > d) b = (byte)(c.B - d);
Color c1 = Color.FromArgb(r,g,b);
return c1;
}
public static Color GetLightColor(Color c,byte d)
{
byte r = 255 ;
byte g = 255 ;
byte b = 255 ;
if (c.R + d < 255) r = (byte)(c.R + d);
if (c.G + d < 255) g = (byte)(c.G + d);
if (c.B + d < 255) b = (byte)(c.B + d);
Color c2 = Color.FromArgb(r,g,b);
return c2;
}
/// <summary>
/// Method which checks is particular point is in rectangle
/// </summary>
/// <param name="p">Point to be Chaecked</param>
/// <param name="r">Rectangle</param>
/// <returns>true is Point is in rectangle, else false</returns>
public static bool IsPointinRectangle(Point p ,Rectangle r)
{
bool flag = false;
if (p.X > r.X && p.X < r.X + r.Width && p.Y > r.Y && p.Y < r.Y + r.Height)
{
flag = true;
}
return flag;
}
public static void DrawInsetCircle(ref Graphics g,Rectangle r,Pen p)
{
Pen p1 = new Pen(GetDarkColor(p.Color,50));
Pen p2 = new Pen(GetLightColor(p.Color,50));
for (int i=0;i<p.Width;i++)
{
Rectangle r1 = new Rectangle(r.X +i,r.Y +i,r.Width-i*2,r.Height-i*2);
g.DrawArc(p2,r1,-45,180);
g.DrawArc(p1,r1,135,180);
}
}
}
}