Search code examples
c#devexpresspdf-viewer

Disable Control Print (Ctrl + P) in Pdf Viewer Devexpress Winform


I want to protect PDF in PdfViewer DevExpress, prevent user to print, save as and user just may to view only. I have created simple project and run well, but when user press Ctrl + P, user still can print that file. Any suggest to solve this?

This the image that I attach, and I don't want user show this and when user press Ctrl + P they will look that this document PDF is protected:

Print

I try this code in Key_Down event of PdfViewer:

private void pdfViewer1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Control && e.KeyCode == Keys.P) //detect key ctrl+p
    {
        e.Handled = false;
        MessageBox.Show("This Document is Protected !", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        return;
    }
    base.OnKeyDown(e);
}

It doesn't work.


Solution

  • If you want to prevent your PdfViewer from recieving Ctrl + P then you must use KeyEventArgs.SuppressKeyPress property. Here is example:

    private void pdfViewer1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Control && e.KeyCode == Keys.P) //detect key ctrl+p
        {
            e.SuppressKeyPress = true; //<= Set it to true.
            MessageBox.Show("This Document is Protected !", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            return;
        }        
    }