forked from jaysonragasa/MultiRDPClient.NET
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLabelRotate.cs
More file actions
170 lines (156 loc) · 4.46 KB
/
LabelRotate.cs
File metadata and controls
170 lines (156 loc) · 4.46 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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace CommonTools
{
public class LabelRotate : Control
{
float m_textAngle = 0;
ContentAlignment m_rotatePointAlignment = ContentAlignment.MiddleCenter;
ContentAlignment m_textAlignment = ContentAlignment.MiddleLeft;
public new string Text
{
get { return base.Text; }
set
{
base.Text = value;
Refresh();
}
}
public float TextAngle
{
get { return m_textAngle; }
set
{
m_textAngle = value;
Invalidate();
}
}
public ContentAlignment TextAlign
{
get { return m_textAlignment; }
set
{
m_textAlignment = value;
Invalidate();
}
}
public ContentAlignment RotatePointAlignment
{
get { return m_rotatePointAlignment; }
set
{
m_rotatePointAlignment = value;
Invalidate();
}
}
Color m_frameColor = Color.CadetBlue;
public LabelRotate()
{
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.Text = string.Empty;
this.DoubleBuffered = true;
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true);
}
protected override void OnPaint(PaintEventArgs e)
{
using (SolidBrush b = new SolidBrush(BackColor))
{
e.Graphics.FillRectangle(b, ClientRectangle);
}
RectangleF lr = ClientRectangleF;
Pen framepen = new Pen(m_frameColor, 1);
Util.DrawFrame(e.Graphics, lr, 6, m_frameColor);
if (Text.Length > 0)
{
StringFormat format = new StringFormat();
string alignment = TextAlign.ToString();
if (((int)TextAlign & (int)(ContentAlignment.BottomLeft | ContentAlignment.MiddleLeft | ContentAlignment.TopLeft)) != 0)
format.Alignment = StringAlignment.Near;
if (((int)TextAlign & (int)(ContentAlignment.BottomCenter | ContentAlignment.MiddleCenter | ContentAlignment.TopCenter)) != 0)
format.Alignment = StringAlignment.Center;
if (((int)TextAlign & (int)(ContentAlignment.BottomRight | ContentAlignment.MiddleRight | ContentAlignment.TopRight)) != 0)
format.Alignment = StringAlignment.Far;
if (((int)TextAlign & (int)(ContentAlignment.BottomLeft | ContentAlignment.BottomCenter | ContentAlignment.BottomRight)) != 0)
format.LineAlignment = StringAlignment.Far;
if (((int)TextAlign & (int)(ContentAlignment.MiddleLeft | ContentAlignment.MiddleCenter | ContentAlignment.MiddleRight)) != 0)
format.LineAlignment = StringAlignment.Center;
if (((int)TextAlign & (int)(ContentAlignment.TopLeft | ContentAlignment.TopCenter | ContentAlignment.TopRight)) != 0)
format.LineAlignment = StringAlignment.Near;
Rectangle r = ClientRectangle;
r.X += Padding.Left;
r.Y += Padding.Top;
r.Width -= Padding.Right;
r.Height -= Padding.Bottom;
using (SolidBrush b = new SolidBrush(ForeColor))
{
if (TextAngle == 0)
{
e.Graphics.DrawString(Text, Font, b, r, format);
}
else
{
PointF center = Util.Center(ClientRectangle);
switch (RotatePointAlignment)
{
case ContentAlignment.TopLeft:
center.X = r.Left;
center.Y = r.Top;
break;
case ContentAlignment.TopCenter:
center.Y = r.Top;
break;
case ContentAlignment.TopRight:
center.X = r.Right;
center.Y = r.Top;
break;
case ContentAlignment.MiddleLeft:
center.X = r.Left;
break;
case ContentAlignment.MiddleCenter:
break;
case ContentAlignment.MiddleRight:
center.X = r.Right;
break;
case ContentAlignment.BottomLeft:
center.X = r.Left;
center.Y = r.Bottom;
break;
case ContentAlignment.BottomCenter:
center.Y = r.Bottom;
break;
case ContentAlignment.BottomRight:
center.X = r.Right;
center.Y = r.Bottom;
break;
}
center.X += Padding.Left;
center.Y += Padding.Top;
center.X -= Padding.Right;
center.Y -= Padding.Bottom;
e.Graphics.TranslateTransform(center.X, center.Y);
e.Graphics.RotateTransform(TextAngle);
e.Graphics.DrawString(Text, Font, b, new PointF(0,0), format);
e.Graphics.ResetTransform();
}
}
}
RaisePaintEvent(this, e);
}
protected RectangleF ClientRectangleF
{
get
{
RectangleF r = ClientRectangle;
r.Width -= 1;
r.Height -= 1;
return r;
}
}
}
}