/
CustomFormPainter.cs
46 lines (44 loc) · 1.79 KB
/
CustomFormPainter.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
using DevExpress.Skins;
using DevExpress.Skins.XtraForm;
using DevExpress.Utils;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace WindowsApplication1 {
public class CustomFormPainter : FormPainter {
public CustomFormPainter(Control owner, DevExpress.Skins.ISkinProvider provider)
: base(owner, provider) {
}
private HorzAlignment _CaptionAlignment = HorzAlignment.Default;
public HorzAlignment CaptionAlignment {
get {
return _CaptionAlignment;
}
set {
_CaptionAlignment = value;
}
}
public CustomFormPainter(XtraForm1 owner, DevExpress.LookAndFeel.UserLookAndFeel provider, HorzAlignment captionAlignment)
: base(owner, provider) {
CaptionAlignment = captionAlignment;
}
protected override void DrawText(DevExpress.Utils.Drawing.GraphicsCache cache) {
string text = Text;
if (text == null || text.Length == 0 || TextBounds.IsEmpty) {
return;
}
AppearanceObject appearance = new AppearanceObject(GetDefaultAppearance());
appearance.TextOptions.Trimming = Trimming.EllipsisCharacter;
appearance.TextOptions.HAlignment = CaptionAlignment;
if (AllowHtmlDraw) {
DrawHtmlText(cache, appearance);
return;
}
Rectangle r = RectangleHelper.GetCenterBounds(TextBounds, new Size(TextBounds.Width, CalcTextHeight(cache, appearance)));
DrawTextShadow(cache, appearance, r);
cache.DrawString(text, appearance.Font, appearance.GetForeBrush(cache), r, appearance.GetStringFormat());
}
}
}