- [DEVEXPRESS] Hướng dẫn bật tính năng Scroll Pixcel in Touch trên GridView
- [DEVEXPRESS] Hướng dẫn sử dụng TileBar viết ứng dụng duyệt hình ảnh Winform
- [DEVEXPRESS] Tô màu border TextEdit trên Winform
- [C#] Lấy dữ liệu từ Console Write hiển thị lên textbox Winform
- [C#] Hiển thị Progress bar trên Window Console
- [C#] Di chuyển control Runtime và lưu layout trên winform
- [SQLSERVER] Sử dụng hàm NULL IF
- [C#] Chia sẽ source code mã đi tuần bằng giao diện Winform
- [C#] Flash Window in Taskbar Winform
- Download và Giải nén tập tin File sử dụng Powershell
- [C#] Hướng dẫn cách lấy thông tin đăng nhập tài khoản và mật khẩu web browser trên windows
- [VB.NET] CRUD Thêm xóa sửa tìm kiếm Realtime FireBase
- [C#] Hiển thị thông báo Toast Message trong lập trình Winform
- [C#] Cấu hình định dạng ngày tháng, thời gian trên Windows cho ứng dụng Winform
- [C#] Rút gọn đường dẫn link url với TinyURL API
- [C#] Hướng dẫn cách bo tròn winform with Radius
- [C#] Chia sẽ class BackGroundOverlay Show Modal cho Winform
- [C#] Hướng dẫn Flip Image Winform
- [C#] Invoke là gì? cách sử dụng phương thức Invoke()
- [C#] Hướng dẫn chia sẽ file, folder từ ứng dụng sang Zalo Chat
[DEVEXPRESS] Demo ứng dụng tải hình ảnh Bất đồng bộ vào TileView trong Gridview của Devexpress
Xin chào các bạn, bài viết hôm nay mình sẽ tiếp tục hướng dẫn các bạn cách tải hình ảnh bất đồng bộ vào Gridview dưới góc nhìn layout Tileview Devexpress C#.
[DEVEXPRESS] Load Image Async to TileView C#
Bài này mình sẽ nói về TileView Devexpress, khi các bạn tải hình ảnh dạng Thumbnail vào Tileview.
Nếu các bạn có ít hình load vào thì không sao, nhưng nếu bạn có khoảng 100 hoặc 1000 hình ảnh cần load vào Tileview.
Nếu các bạn tải hình ảnh bình thường (đồng bộ) thì ứng dụng của các bạn sẽ bị treo.
Và mong muốn là hình nhiều, nhưng khi mình scroll đến đâu hình ảnh mới bắt đầu load và tải bằng async (bất đồng bộ).
Giao diện Demo ứng dụng Load Async Image to TileView C#
Full source code load async Image c#:
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;
tileView1.ColumnSet.BackgroundImageColumn = colName;
tileView1.OptionsImageLoad.RandomShow = true;
tileView1.OptionsImageLoad.LoadThumbnailImagesFromDataSource = false;
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) {
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; }
}
}
Thanks for watching!