在 WinForms/WPF 查看器中延迟加载 DOCX 页面
2024/04/19
/// <summary>
/// The images manager for an image viewer.
/// </summary>
Vintasoft.Imaging.UI.ImageViewerImagesManager _imagesManager;
/// <summary>
/// Initializes a new instance of the <see cref="MainForm1"/> class.
/// </summary>
public MainForm1()
{
InitializeComponent();
// create images manager
_imagesManager = new Vintasoft.Imaging.UI.ImageViewerImagesManager(imageViewer1);
// specify that manager should retrieve information about image from file during 1 second, add images to an image viewer,
// do previous steps until information about all images will not be retrieved
_imagesManager.IntermediateAddInterval = 1000;
// specify that manager should work asynchronously
_imagesManager.IsAsync = true;
_imagesManager.ImageSourceAddException += ImagesManager_ImageSourceAddException;
}
/// <summary>
/// Opens an image file.
/// </summary>
/// <param name="filename">The filename.</param>
internal void OpenImageFile(string filename)
{
// cancel previous file opening process
CancelOpening();
// clear image collection of manager
_imagesManager.Images.ClearAndDisposeItems();
// add image file to the manager
_imagesManager.Add(filename);
}
/// <summary>
/// Cancels the opening of a file.
/// </summary>
private void CancelOpening()
{
_imagesManager.Cancel();
}
private void ImagesManager_ImageSourceAddException(object sender, Vintasoft.Imaging.ImageSourceExceptionEventArgs e)
{
string message = string.Format("Cannot open {0} : {1}", System.IO.Path.GetFileName(e.SourceFilename), e.Exception.Message);
System.Windows.Forms.MessageBox.Show(message, "Error");
}