This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
Form1.vb
108 lines (94 loc) · 3.15 KB
/
Form1.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
107
108
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports DevExpress.XtraEditors
Imports DevExpress.Utils
Imports System.Collections
Namespace WindowsApplication1
Partial Public Class Form1
Inherits Form
Private Function CreateTable(ByVal RowCount As Integer) As DataTable
Dim tbl As New DataTable()
tbl.Columns.Add("Name", GetType(String))
tbl.Columns.Add("ID", GetType(Integer))
tbl.Columns.Add("Number", GetType(Integer))
tbl.Columns.Add("Date", GetType(DateTime))
For i As Integer = 0 To RowCount - 1
tbl.Rows.Add(New Object() { String.Format("Name{0}", i), i, 3 - i, DateTime.Now.AddDays(i) })
Next i
Return tbl
End Function
Public Sub New()
InitializeComponent()
dataGridView1.DataSource = CreateTable(20)
dataNavigator1.DataSource = dataGridView1.DataSource
End Sub
End Class
Public Class DataNavigatorButtonCaptionHelper
Inherits Component
Private _SelectedNavigator As DataNavigator
Public Property SelectedNavigator() As DataNavigator
Get
Return _SelectedNavigator
End Get
Set(ByVal value As DataNavigator)
BeforeSelectedNavigatorChanged(value)
_SelectedNavigator = value
AfterSelectedNavigatorChanged()
End Set
End Property
Public _imageList As ImageList
Private Sub BeforeSelectedNavigatorChanged(ByVal newNavigator As DataNavigator)
If _SelectedNavigator IsNot Nothing Then
_SelectedNavigator.Buttons.ImageList = Nothing
End If
If newNavigator IsNot Nothing Then
newNavigator.Buttons.ImageList = _imageList
End If
End Sub
Private Sub TraverseCollection(ByVal collection As ICollection)
Dim col1 As NavigatorButtonCollectionBase = TryCast(collection, NavigatorButtonCollectionBase)
Dim col2 As NavigatorCustomButtons = TryCast(collection, NavigatorCustomButtons)
For i As Integer = 0 To collection.Count - 1
Dim button As NavigatorButtonBase = Nothing
If col1 IsNot Nothing Then
button = col1(i)
Else
button = col2(i)
End If
If button.Tag Is Nothing Then
Continue For
End If
_imageList.Images.Add(GetBitmap(button.Tag))
button.ImageIndex = _imageList.Images.Count - 1
Next i
End Sub
Private Sub AfterSelectedNavigatorChanged()
If SelectedNavigator Is Nothing Then
Return
End If
TraverseCollection(SelectedNavigator.Buttons.ButtonCollection)
TraverseCollection(SelectedNavigator.Buttons.CustomButtons)
End Sub
Private Function GetBitmap(ByVal text As Object) As Bitmap
Dim image As New Bitmap(_imageList.ImageSize.Width, _imageList.ImageSize.Height)
Dim g As Graphics = Graphics.FromImage(image)
Dim rect As New Rectangle(New Point(0, 0), image.Size)
g.FillRectangle(Brushes.White, rect)
Dim sf As New StringFormat()
sf.Alignment = StringAlignment.Center
g.DrawString(text.ToString(), AppearanceObject.DefaultFont, Brushes.Black, rect, sf)
image.MakeTransparent()
Return image
End Function
Public Sub New()
_imageList = New ImageList()
_imageList.ImageSize = New Size(70, 20)
End Sub
End Class
End Namespace