This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SkinButtonHelper.cs
68 lines (63 loc) · 2.62 KB
/
SkinButtonHelper.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.LookAndFeel;
using DevExpress.Skins;
using DevExpress.Utils;
using DevExpress.Utils.Drawing;
namespace DXApplication191 {
class SkinButtonPaintHelper {
DevExpress.Utils.AppearanceObject _appearance;
Image _image;
Rectangle _buttonRectangle;
public AppearanceObject AppearanceObject {
get {
if (_appearance == null)
_appearance = new AppearanceObject();
return _appearance;
}
set {
_appearance = value;
}
}
public Image ButtonImage {
get { return _image; }
set { _image = value; }
}
public Rectangle ButtonRectangle { get { return _buttonRectangle; } set { _buttonRectangle = value; } }
public string ButtonText { get; set; }
public SkinButtonPaintHelper() {
AppearanceObject.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
AppearanceObject.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center;
}
public void DrawButton(PaintEventArgs args, ObjectState state) {
using (GraphicsCache cache = new GraphicsCache(args)) {
SkinElement element = CommonSkins.GetSkin(UserLookAndFeel.Default)[CommonSkins.SkinButton];
SkinElementInfo info = new SkinElementInfo(element, ButtonRectangle);
if (state == ObjectState.Normal) info.ImageIndex = 0;
if (state == ObjectState.Hot) info.ImageIndex = 1;
if (state == ObjectState.Pressed) info.ImageIndex = 2;
DrawSkinImage(cache, info);
DrawText(cache);
DrawImage(cache);
}
}
void DrawSkinImage(GraphicsCache cache, SkinElementInfo info) {
ObjectPainter.DrawObject(cache, SkinElementPainter.Default, info);
}
void DrawText(GraphicsCache cache) {
AppearanceObject.DrawString(cache, ButtonText, ButtonRectangle);
}
void DrawImage(GraphicsCache cache) {
if (ButtonImage == null) return;
Rectangle imageBounds = GetImageBounds(ButtonRectangle, ButtonImage.Size);
cache.Graphics.DrawImage(ButtonImage, imageBounds);
}
Rectangle GetImageBounds(Rectangle buttonBounds, Size imageSize) {
return ImageLayoutHelper.GetImageBounds(buttonBounds, imageSize, ImageScaleMode.Clip, ImageAlignmentMode.MiddleLeft);
}
}
}