Search

Atalasoft Knowledge Base

HOWTO: Customize Thumbnail Drawing in ThumbnailView / FolderThumbnailView (Windows Forms Control)

Administrator
DotImage

In DotImage 4.0 we added many properties to the ThumbnailView and FolderThumbnailView that allow customizing the way thumbnails appear. However, should you need even more control over the look of the thumbnails it's possible to handle the total drawing code.

To override the internal thumbnail drawing add an event handler for the PaintThumbnail event of the ThumbnailView or FolderThumbnailView control. The PaintThumbnailEventArgs provides all of the information you need to render the item yourself.

private void folderThumbnailView1_PaintThumbnail(object sender, Atalasoft.Imaging.WinControls.PaintThumbnailEventArgs e)
{
	if (e.Thumbnail.Image != null)
	{
		// Center the thumbnail and offset by the scroll position.
		Rectangle rc = new Rectangle(e.ItemBounds.Image.X + 
					((e.ItemBounds.Image.Width - e.Thumbnail.Image.Width) / 2) + 
					e.ScrollPosition.X, e.ItemBounds.Image.Y + 
					((e.ItemBounds.Image.Height - e.Thumbnail.Image.Height) / 2) + 
					e.ScrollPosition.Y, e.Thumbnail.Image.Width, e.Thumbnail.Image.Height);
		e.Thumbnail.Image.Draw(e.Graphics, rc);
	}
    
    if (e.Thumbnail.Text.Length > 0)
    {
    	e.Graphics.DrawString(e.Thumbnail.Text, 
    				this.folderThumbnailView1.Font, 
    				Brushes.Black, 
    				new RectangleF(e.ItemBounds.Caption.X + e.ScrollPosition.X, 
    						e.ItemBounds.Caption.Y + e.ScrollPosition.Y, 
    						e.ItemBounds.Caption.Width, 
    						e.ItemBounds.Caption.Height), 
    				this.folderThumbnailView1.CaptionFormat);
    }	
    
    if (e.Thumbnail == this.folderThumbnailView1.HoverItem)
    {
    	ControlPaint.DrawBorder3D(e.Graphics, 
    				new Rectangle(e.ItemBounds.Image.X + e.ScrollPosition.X, 
    						e.ItemBounds.Image.Y + e.ScrollPosition.Y, 
    						e.ItemBounds.Image.Width, 
    						e.ItemBounds.Image.Height), 
    				Border3DStyle.Raised);
    }

Original Article:
Q10148 - HOWTO: Custom Thumbnail Drawing

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