This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
RibbonLogoHelper.vb
106 lines (93 loc) · 2.71 KB
/
RibbonLogoHelper.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
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
Imports DevExpress.XtraBars.Ribbon
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Linq
Imports System.Text
Imports DevExpress.XtraBars.Ribbon.ViewInfo
Imports System.Drawing
Namespace DevExpress.XtraBars.Ribbon
<DesignerCategory(""), Designer("")>
Public Class RibbonLogoHelper
Inherits Component
Private _Image As Image
Private _RibbonControl As RibbonControl
Public Property RibbonControl() As RibbonControl
Get
Return _RibbonControl
End Get
Set(ByVal value As RibbonControl)
If value Is _RibbonControl Then
Return
End If
Dim prevValue As RibbonControl = _RibbonControl
_RibbonControl = value
OnRibbonChanged(prevValue, _RibbonControl)
End Set
End Property
Private Sub OnRibbonChanged(ByVal prevValue As RibbonControl, ByVal ribbonControl As RibbonControl)
If prevValue IsNot Nothing Then
RemoveHandler prevValue.Paint, AddressOf ribbonControl_Paint
End If
If ribbonControl IsNot Nothing Then
AddHandler ribbonControl.Paint, AddressOf ribbonControl_Paint
ribbonControl.Invalidate()
End If
End Sub
Private Sub ribbonControl_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
DrawRibbonLogo(e.Graphics)
End Sub
Public Property Image() As Image
Get
Return _Image
End Get
Set(ByVal value As Image)
If value Is _Image Then
Return
End If
_Image = value
OnImageChanged()
End Set
End Property
Private Sub OnImageChanged()
If RibbonControl IsNot Nothing Then
RibbonControl.Invalidate()
End If
End Sub
Private Sub DrawRibbonLogo(ByVal graphics As Graphics)
If Image Is Nothing Then
Return
End If
Dim ribbonViewInfo As RibbonViewInfo = RibbonControl.ViewInfo
If ribbonViewInfo Is Nothing Then
Return
End If
Dim panelViewInfo As RibbonPanelViewInfo = ribbonViewInfo.Panel
If panelViewInfo Is Nothing Then
Return
End If
Dim bounds As Rectangle = panelViewInfo.Bounds
Dim minX As Integer = bounds.X
Dim groups As RibbonPageGroupViewInfoCollection = panelViewInfo.Groups
If groups Is Nothing Then
Return
End If
If groups.Count > 0 Then
minX = groups(groups.Count - 1).Bounds.Right
End If
If bounds.Height < Image.Height Then
Return
End If
Dim offset As Integer = (bounds.Height - Image.Height) \ 2
Dim width As Integer = Image.Width + 15
bounds.X = bounds.Width - width
If bounds.X < minX Then
Return
End If
bounds.Width = width
bounds.Y += offset
bounds.Height = Image.Height
graphics.DrawImage(Image, New Rectangle(bounds.Location, Image.Size), New Rectangle(Point.Empty, Image.Size), GraphicsUnit.Pixel)
End Sub
End Class
End Namespace