-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOffice2007Helpers.cs
133 lines (122 loc) · 3.58 KB
/
Office2007Helpers.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/********************************************************************/
/* Office 2007 Renderer Project */
/* */
/* Use the Office2007Renderer class as a custom renderer by */
/* providing it to the ToolStripManager.Renderer property. Then */
/* all tool strips, menu strips, status strips etc will be drawn */
/* using the Office 2007 style renderer in your application. */
/* */
/* Author: Phil Wright */
/* Website: www.componentfactory.com */
/* Contact: [email protected] */
/********************************************************************/
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
namespace Office2007Rendering
{
/// <summary>
/// Set the SmoothingMode=AntiAlias until instance disposed.
/// </summary>
public class UseAntiAlias : IDisposable
{
#region Instance Fields
private Graphics _g;
private readonly SmoothingMode _old;
#endregion
#region Identity
/// <summary>
/// Initialize a new instance of the UseAntiAlias class.
/// </summary>
/// <param name="g">Graphics instance.</param>
public UseAntiAlias(Graphics g)
{
_g = g;
_old = _g.SmoothingMode;
_g.SmoothingMode = SmoothingMode.AntiAlias;
}
/// <summary>
/// Revert the SmoothingMode back to original setting.
/// </summary>
public void Dispose()
{
_g.SmoothingMode = _old;
}
#endregion
}
/// <summary>
/// Set the TextRenderingHint.ClearTypeGridFit until instance disposed.
/// </summary>
public class UseClearTypeGridFit : IDisposable
{
#region Instance Fields
private Graphics _g;
private readonly TextRenderingHint _old;
#endregion
#region Identity
/// <summary>
/// Initialize a new instance of the UseClearTypeGridFit class.
/// </summary>
/// <param name="g">Graphics instance.</param>
public UseClearTypeGridFit(Graphics g)
{
_g = g;
_old = _g.TextRenderingHint;
_g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
}
/// <summary>
/// Revert the TextRenderingHint back to original setting.
/// </summary>
public void Dispose()
{
_g.TextRenderingHint = _old;
}
#endregion
}
/// <summary>
/// Set the clipping region until instance disposed.
/// </summary>
public class UseClipping : IDisposable
{
#region Instance Fields
private Graphics _g;
private Region _old;
#endregion
#region Identity
/// <summary>
/// Initialize a new instance of the UseClipping class.
/// </summary>
/// <param name="g">Graphics instance.</param>
/// <param name="path">Clipping path.</param>
public UseClipping(Graphics g, GraphicsPath path)
{
_g = g;
_old = g.Clip;
Region clip = _old.Clone();
clip.Intersect(path: path);
_g.Clip = clip;
}
/// <summary>
/// Initialize a new instance of the UseClipping class.
/// </summary>
/// <param name="g">Graphics instance.</param>
/// <param name="region">Clipping region.</param>
public UseClipping(Graphics g, Region region)
{
_g = g;
_old = g.Clip;
Region clip = _old.Clone();
clip.Intersect(region: region);
_g.Clip = clip;
}
/// <summary>
/// Revert clipping back to origina setting.
/// </summary>
public void Dispose()
{
_g.Clip = _old;
}
#endregion
}
}