Working with ErrorOccurred Event in WinForms PDF Viewer

5 Sep 20251 minute to read

PDF Viewer provides support to identify the error using the ErrorOccurred Event,The ErrorOccurred event in the PdfViewerControl is triggered whenever an error occurs within the control. This event provides an opportunity to handle errors effectively by allowing developers to log the details or display appropriate messages to users when an issue arises within the PdfViewerControl.

public Form1()
{
    InitializeComponent();
    PdfViewer.ErrorOccurred += PdfViewer_ErrorOccurred;
}

private void PdfViewer_ErrorOccurred(object sender, ErrorOccurredEventArgs e)
{
    // Log error message
    Console.WriteLine("Error occurred in PdfViewerControl: " + e.Message);

    // Display error message to the user
    MessageBox.Show("An error occurred while viewing the PDF: " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}