forked from fdorg/flashdevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawHelper.cs
More file actions
33 lines (30 loc) · 1.02 KB
/
DrawHelper.cs
File metadata and controls
33 lines (30 loc) · 1.02 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
using System;
using System.Drawing;
namespace PluginCore.Helpers
{
public class DrawHelper
{
/// <summary>
/// Measures the actual width of the text
/// http://www.codeproject.com/KB/GDI-plus/measurestring.aspx
/// </summary>
public static Int32 MeasureDisplayStringWidth(Graphics graphics, String text, Font font)
{
try
{
StringFormat format = new StringFormat();
RectangleF rect = new RectangleF(0, 0, 1000, 1000);
CharacterRange[] ranges = { new CharacterRange(0, text.Length) };
Region[] regions = new Region[1];
format.SetMeasurableCharacterRanges(ranges);
regions = graphics.MeasureCharacterRanges(text, font, rect, format);
rect = regions[0].GetBounds(graphics);
return (Int32)rect.Right;
}
catch (IndexOutOfRangeException)
{
return 0;
}
}
}
}