This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
SkinnedStandardButton.vb
68 lines (60 loc) · 1.95 KB
/
SkinnedStandardButton.vb
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
Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraEditors.Drawing
Imports DevExpress.LookAndFeel
Imports DevExpress.XtraEditors.Controls
Imports DevExpress.Utils.Drawing
Imports DevExpress.Utils
Imports System.ComponentModel
Namespace WindowsApplication1
<System.ComponentModel.DesignerCategory("")> _
Public Class SkinnedStandardButton
Inherits Button
Private _Button As New EditorButton(ButtonPredefines.Glyph)
Private _Painter As SkinEditorButtonPainter
Public Sub New()
_Painter = CreatePainter()
End Sub
Private _UseSkins As Boolean = True
<DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
Public Property UseSkins() As Boolean
Get
Return _UseSkins
End Get
Set(ByVal value As Boolean)
_UseSkins = value
Refresh()
End Set
End Property
Protected Overridable Function CreatePainter() As SkinEditorButtonPainter
Return New SkinEditorButtonPainter(UserLookAndFeel.Default)
End Function
Private Function GetObjectState() As ObjectState
Dim location As Point = PointToScreen(New Point(0, 0))
Dim mouseInButton As Boolean = New Rectangle(location, New Size(Width, Height)).Contains(Control.MousePosition)
If (Not mouseInButton) OrElse DesignMode Then
Return ObjectState.Normal
End If
If Control.MouseButtons = MouseButtons.Left Then
Return ObjectState.Pressed
Else
Return ObjectState.Hot
End If
End Function
Protected Overrides Sub OnPaint(ByVal pevent As PaintEventArgs)
If UseSkins Then
Dim args As New EditorButtonObjectInfoArgs(New GraphicsCache(pevent.Graphics), _Button, AppearanceObject.EmptyAppearance)
args.Bounds = New Rectangle(0, 0, Width, Height)
args.BuiltIn = False
args.FillBackground = False
args.State = GetObjectState()
args.Button.Caption = Text
_Painter.DrawObject(args)
Else
MyBase.OnPaint(pevent)
End If
End Sub
End Class
End Namespace