I’m working on a WinForms application that uses System.Windows.Forms.PrintPreviewDialog to display a Print Preview dialog. When the user presses ESC in that dialog, I’d like to close the dialog. Unfortunately, I can’t figure out how to do this. I’ve tried to install a KeyDown/PreviewKeyDown event handler, but it never gets called. I also tried setting focus to the dialog (and to its PrintPreviewControl), thinking that was the issue, but that didn’t help either. Does anyone have any idea how to make this work?
I’m working on a WinForms application that uses System.Windows.Forms.PrintPreviewDialog to display a Print Preview
Share
I ended up customizing
PrintPreviewDialogand overriding itsProcessCmdKeymethod to close the form when the user presses ESC. This seems like the cleanest solution.Here’s the code that I wrote: