Click here to Skip to main content
15,887,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Problem
How to prevent print when display data Exist on datatable using printpreview dialog and print document ?
?

I work on csharp app working on visual studio 2015 .

I have data on datatable and show this data exist on datatable when click print button

but problem it print when click print button and printing done to default printer
what i need is prevent from printing data and not allow user to print data when display on windows form ?

can i do that please

What I have tried:

private void button1_Click(object sender, EventArgs e)
        {
            
            PrintDocument document = new PrintDocument();
            
            document.PrintPage += new PrintPageEventHandler(document_PrintPage);
            

            PrintPreviewDialog ppDialog = new PrintPreviewDialog();
            ((ToolStripButton)((ToolStrip)ppDialog.Controls[1]).Items[0]).Enabled = false;
            ppDialog.Document = document;
           
            ppDialog.Show();
           
        }
Posted
Updated 1-Feb-19 5:14am
v2

1 solution

That doesn't seem to make any real sense: your app is in control of printing and with a PrintDocument you control when it gets printed, and exactly what gets printed. Nothing gets printed until you call the myPrintDocumentInstance.Print method.

So if you want to restrict what gets printed, just don't output it in the document_PrintPage event handler.

Other ways you can't prevent: if the user can read it, it's on the screen - and the screen can be snapshotted and printed, edited, or saved to disk as a bitmap. You can;t prevent that.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900