-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathVerticalBarLabel.cs
58 lines (57 loc) · 2.19 KB
/
VerticalBarLabel.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
using System;
using System.Windows.Forms;
using System.Drawing;
namespace DigiRite
{
class VerticalBarLabel : Label
{
private ushort m_Value = 0;
public ushort Value
{
get { return m_Value; }
set { m_Value = value; Invalidate(); }
}
protected const ushort RED_BOUNDARY = 0x4000;
protected float fraction(ushort v)
{
return ((float)v) / 0x7FFF;
}
protected override void OnPaint(PaintEventArgs e)
{
Color fillColor = BackColor;
System.Drawing.Brush fb = new SolidBrush(fillColor);
using (fb)
e.Graphics.FillRectangle(fb, ClientRectangle);
Pen blackPen = new Pen(Color.Black);
using (blackPen)
{
if (Value != 0)
{
Brush greenBrush = new SolidBrush(Color.Green);
using (greenBrush)
{
var f = fraction(Value);
var Height = Size.Height - 2;
var Width = Size.Width - 2;
Rectangle barRect = new Rectangle(1, 1+ (int)((1 - f) * Height), Width, (int)(f * Height));
bool anyRed = Value > RED_BOUNDARY;
if (anyRed)
{
Brush redBrush = new SolidBrush(Color.Red);
using (redBrush)
e.Graphics.FillRectangle(redBrush, barRect);
}
ushort GreenHeight = anyRed ? RED_BOUNDARY : Value;
var greenF = fraction(GreenHeight);
Rectangle greenRect = new Rectangle(1, 1+(int)((1 - greenF) * Height), Width, (int)(greenF * Height));
e.Graphics.FillRectangle(greenBrush, greenRect);
{
e.Graphics.DrawRectangle(blackPen, barRect);
}
}
}
e.Graphics.DrawRectangle(blackPen, new Rectangle(0, 0, Size.Width-1, Size.Height-1));
}
}
}
}