-
Notifications
You must be signed in to change notification settings - Fork 2
/
Form1.vb
73 lines (61 loc) · 2.83 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
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Namespace TileView_ManualThumbs
Public Partial Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private textures As List(Of Texture)
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
InitData()
gridControl1.DataSource = textures
tileView1.OptionsTiles.ItemSize = New Size(90, 40)
AddHandler tileView1.GetThumbnailImage, AddressOf TileView1_GetThumbnailImage
' Specify a column that provides information on images to render.
tileView1.ColumnSet.BackgroundImageColumn = colName
tileView1.OptionsImageLoad.RandomShow = True
tileView1.OptionsImageLoad.LoadThumbnailImagesFromDataSource = False
' Enable async image load.
tileView1.OptionsImageLoad.AsyncLoad = True
End Sub
Private Sub TileView1_GetThumbnailImage(ByVal sender As Object, ByVal e As DevExpress.Utils.ThumbnailImageEventArgs)
Dim colorName As String = textures(e.DataSourceIndex).Name
e.ThumbnailImage = GetImage(e.DesiredThumbnailSize, colorName)
End Sub
Private Function GetImage(ByVal imageSize As Size, ByVal colorName As String) As Image
'Generate a thumbnail
Dim image As Bitmap = New Bitmap(imageSize.Width, imageSize.Height)
Using graphics As Graphics = Graphics.FromImage(image)
Dim tileColor As Color = Color.FromName(colorName)
Dim grUnit As GraphicsUnit = GraphicsUnit.Pixel
Dim imageRect As RectangleF = image.GetBounds(grUnit)
Using brush As LinearGradientBrush = New LinearGradientBrush(imageRect, Color.White, Color.White, 45, False)
Dim cblend As ColorBlend = New ColorBlend(4)
cblend.Colors = New Color(3) {Color.White, tileColor, tileColor, Color.White}
cblend.Positions = New Single(3) {0F, 0.5F, 0.7F, 1F}
brush.InterpolationColors = cblend
graphics.FillRectangle(brush, imageRect)
End Using
End Using
Return image
End Function
Private Sub InitData()
textures = New List(Of Texture)()
Dim colorsArray As Array = [Enum].GetNames(GetType(KnownColor))
For Each colorName In colorsArray
textures.Add(New Texture(colorName.ToString()))
Next
End Sub
End Class
Public Class Texture
Public Sub New(ByVal name As String)
Me.Name = name
End Sub
Public Property Name As String
End Class
End Namespace