WinForms: Get information about thumbnail in the thumbnail viewer.
Posted: Wed Feb 15, 2017 12:26 pm
This topic contains C# code snippet that shows how to get information about thumbnail image (filename and page index) in the thumbnail viewer.
Source codes of WinForms application for VintaSoft Imaging .NET SDK 12 can be downloaded here.
Code: Select all
using System;
using System.Text;
using System.Windows.Forms;
using Vintasoft.Imaging;
using Vintasoft.Imaging.UI;
namespace WindowsFormsApplication1
{
/// <summary>
/// Main form.
/// </summary>
public partial class MainForm : Form
{
/// <summary>
/// Initializes a new instance of the <see cref="MainForm"/> class.
/// </summary>
public MainForm()
{
InitializeComponent();
thumbnailViewer1.FocusedIndexChanged +=
new EventHandler<FocusedIndexChangedEventArgs>(thumbnailViewer1_FocusedIndexChanged);
}
/// <summary>
/// Clears image collection of thumbnail viewer and
/// adds image(s) to an image collection of thumbnail viewer.
/// </summary>
private void openButton_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
thumbnailViewer1.Images.ClearAndDisposeItems();
foreach (string fileName in openFileDialog1.FileNames)
{
try
{
thumbnailViewer1.Images.Add(fileName);
}
catch (Exception exc)
{
MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
/// <summary>
/// Focused image is changed.
/// </summary>
private void thumbnailViewer1_FocusedIndexChanged(object sender, FocusedIndexChangedEventArgs e)
{
ThumbnailViewer viewer = (ThumbnailViewer)sender;
VintasoftImage image = null;
if (e.FocusedIndex != -1)
image = viewer.Images[e.FocusedIndex];
ShowImageInfo(image);
}
/// <summary>
/// Shows the image information.
/// </summary>
/// <param name="image">The image.</param>
private void ShowImageInfo(VintasoftImage image)
{
if (image == null)
imageInfoTextBox.Text = string.Empty;
else
{
ImageSourceInfo sourceInfo = image.SourceInfo;
StringBuilder builder = new StringBuilder();
builder.AppendFormat("File: {0}", sourceInfo.Filename);
builder.AppendLine();
if (sourceInfo.PageCount > 1)
{
builder.AppendFormat("Page: {0}/{1}", sourceInfo.PageIndex + 1, sourceInfo.PageCount);
builder.AppendLine();
}
imageInfoTextBox.Text = builder.ToString();
}
}
/// <summary>
/// Raises the Closed event.
/// </summary>
protected override void OnClosed(EventArgs e)
{
thumbnailViewer1.Images.ClearAndDisposeItems();
base.OnClosed(e);
}
}
}
Source codes of WinForms application for VintaSoft Imaging .NET SDK 12 can be downloaded here.