Screen capturing a WPF form

In this article I explained how a form with a DocumentViewer control can be used to render, save, and print official documents - like contracts and registration forms. I'm using that same form now behind a Print Screen button or command, accessible from the application's main toolbar. It allows the user to generate a screenshot of the application's main window. Here's what you can type in the button_clicked or the command_executed code:

        /// <summary>
        /// Opens a ReportWindow with a screenshot of the whole main window and its contents.
        /// </summary>
        /// <param name="sender">The (toolbar) button that was clicked.</param>
        /// <param name="e">The Event Args.</param>
        private void PrintScreenButton_Click(object sender, RoutedEventArgs e)
            XpsWysiwyg reportWindow = new XpsWysiwyg();
            reportWindow.Title = "Schermafdruk"; // That's just Dutch for 'ScreenShot' ;-)
            reportWindow.WindowState = WindowState.Normal;
            reportWindow.ElementToRender = this; // The Main Window
            reportWindow.documentViewer1.FitToMaxPagesAcross(1); // Zoom to whole Page

Here's how it looks like in a real application:

1 comment:

  1. If you need your ex-girlfriend or ex-boyfriend to come crawling back to you on their knees (no matter why you broke up) you gotta watch this video
    right away...

    (VIDEO) Want your ex CRAWLING back to you...?