Search

Atalasoft Knowledge Base

HOWTO: Customize the look and feel of selected thumbnails using the ThumbnailView control

Administrator
DotImage

Starting with DotImage 4.0, the ThumbnailView control has a PaintThumbnail event that can be used to override how thumbnails are drawn. The following example code can be added to the Folder ThumbnailView Demo to draw a border around a thumbnail when it's selected.

private void folderThumbnailView1_PaintThumbnail(object sender, Atalasoft.Imaging.WinControls.PaintThumbnailEventArgs e)
{ 
	if (e.Thumbnail.Image != null) 
	{  
		Rectangle rc = e.ItemBounds.Image;
		rc.X += (rc.Width - e.Thumbnail.Image.Width) / 2 + e.ScrollPosition.X;
		rc.Y += (rc.Height - e.Thumbnail.Image.Height) / 2 + e.ScrollPosition.Y;
		rc.Width = e.Thumbnail.Image.Width;
		rc.Height = e.Thumbnail.Image.Height;
		e.Thumbnail.Image.Draw(e.Graphics, rc);
	}
	if (e.Thumbnail.Text != null && e.Thumbnail.Text.Length > 0) 
	{  
		StringFormat sf = new StringFormat();
		sf.Alignment = StringAlignment.Center;
		Rectangle crc = new Rectangle(e.ItemBounds.Caption.X + e.ScrollPosition.X,
						e.ItemBounds.Caption.Y + e.ScrollPosition.Y,
						e.ItemBounds.Caption.Width,
						e.ItemBounds.Caption.Height);
		e.Graphics.DrawString(e.Thumbnail.Text, this.folderThumbnailView1.Font, Brushes.Black, crc, sf);
		sf.Dispose();
	}
	if (e.Thumbnail.Selected) 
	{  
		Pen p = new Pen(Color.Aqua, 3);
		e.Graphics.DrawRectangle(p, e.Bounds);
		p.Dispose();
	}
}

Original Article:
Q10157 - HOWTO: Customize the look and feel of selected thumbnails using the ThumbnailView control

Details
Last Modified: Last Month
Last Modified By: Administrator
Type: HOWTO
Article not rated yet.
Article has been viewed 30 times.
Options
Also In This Category