-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathForm1.cs
73 lines (65 loc) · 2.76 KB
/
Form1.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
69
70
71
72
73
using DevExpress.XtraGrid.Views.Tile;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TileView_ManualThumbs {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
List<Texture> textures;
private void Form1_Load(object sender, EventArgs e) {
InitData();
gridControl1.DataSource = textures;
tileView1.OptionsTiles.ItemSize = new Size(90, 40);
tileView1.GetThumbnailImage += 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;
}
private void TileView1_GetThumbnailImage(object sender, DevExpress.Utils.ThumbnailImageEventArgs e) {
string colorName = textures[e.DataSourceIndex].Name;
e.ThumbnailImage = GetImage(e.DesiredThumbnailSize, colorName);
}
private Image GetImage(Size imageSize, string colorName) {
//Generate a thumbnail
Bitmap image = new Bitmap(imageSize.Width, imageSize.Height);
using(Graphics graphics = Graphics.FromImage(image)) {
Color tileColor = Color.FromName(colorName);
GraphicsUnit grUnit = GraphicsUnit.Pixel;
RectangleF imageRect = image.GetBounds(ref grUnit);
using(LinearGradientBrush brush = new LinearGradientBrush(imageRect, Color.White, Color.White, 45, false)) {
ColorBlend cblend = new ColorBlend(4);
cblend.Colors = new Color[4] { Color.White, tileColor, tileColor, Color.White };
cblend.Positions = new float[4] { 0f, 0.5f, 0.7f, 1f };
brush.InterpolationColors = cblend;
graphics.FillRectangle(brush, imageRect);
}
}
return image;
}
private void InitData() {
textures = new List<Texture>();
System.Array colorsArray = Enum.GetNames(typeof(KnownColor));
foreach(var colorName in colorsArray ) {
textures.Add(new Texture(colorName.ToString()));
}
}
}
public class Texture {
public Texture(string name) {
this.Name = name;
}
public string Name { get; set; }
}
}