ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 277.7k

How to prevent user from print content of print documents an

Feb 1 2019 6:27 PM

Problem

How to prevent user from print content of print documents and only show data ?

code below work success and without any problem

only problem is report document.print show data on print preview

and in same time it is print data

actually i dont need to print data

i need to preview data only but code below on print data and show

dialog pox print 1 of page

How to prevent print data please ?

 

  1. code using for button print preview  
  2.   
  3. private void PrintPreview_Click(object sender, EventArgs e)  
  4.         {  
  5.          
  6.             PrintDocument document = new PrintDocument();  
  7.             PrintController printController = new StandardPrintController();  
  8.             document.PrintController = printController;  
  9.             document.PrintPage += new PrintPageEventHandler(document_PrintPage);  
  10.             
  11.             
  12.   
  13.             PrintPreviewDialog ppDialog = new PrintPreviewDialog();  
  14.           
  15.             ((ToolStripButton)((ToolStrip)ppDialog.Controls[1]).Items[0]).Enabled = false;  
  16.             ppDialog.Document = document;  
  17.             ppDialog.Show();  
  18.              
  19.   
  20.            
  21.              
  22.         }  
  1. datatable get checked   
  2.   
  3. public DataTable GetChecked()  
  4.         {  
  5.             DataTable table = new DataTable();  
  6.             table.Columns.Add("MemberCode"typeof(string));  
  7.              
  8.             table.Columns.Add("SpecialCode"typeof(string));  
  9.               
  10.             table.Columns.Add("Name"typeof(string));  
  11.               
  12.             table.Columns.Add("MemberImage"typeof(Byte[]));  
  13.              
  14.               
  15.             for (int i = 0; i < dtDisplayDataPayment.Rows.Count; i++)  
  16.             {  
  17.   
  18.                 bool Ischecked = Convert.ToBoolean(GridFooter.Rows[i].Cells["PrintFlag"].Value);  
  19.                 if (Ischecked == true)  
  20.                 {  
  21.                     DataRow newRow = table.NewRow();  
  22.                     newRow["MemberCode"] = Utilities.ObjectConverter.ConvertToString(dtDisplayDataPayment.Rows[i]["MemberCode"]);  
  23.                     newRow["SpecialCode"] = Utilities.ObjectConverter.ConvertToString(dtDisplayDataPayment.Rows[i]["SpecialCode"]);  
  24.                     newRow["Name"] = Utilities.ObjectConverter.ConvertToString(dtDisplayDataPayment.Rows[i]["Name"]);  
  25.   
  26.                      
  27.                         if (dtDisplayDataPayment.Rows[i]["MemberImage"] != System.DBNull.Value)  
  28.                         {  
  29.                             byte[] photo_aray = (byte[])dtDisplayDataPayment.Rows[i]["MemberImage"];  
  30.                             System.Drawing.ImageConverter converter = new System.Drawing.ImageConverter();  
  31.                             Image img = (Image)converter.ConvertFrom(photo_aray);  
  32.                             newRow["MemberImage"] = imageToByteArray(img);  
  33.                           
  34.                        
  35.                     }  
  36.                       
  37.                      
  38.                     table.Rows.Add(newRow);  
  39.                 }  
  40.             }  
  41.   
  42.             return table;  
  43.   
  44.   
  45.         }  
  46.   
  47. void document_PrintPage(object sender, PrintPageEventArgs e)  
  48.         {  
  49.             dtGetChecked = GetChecked();  
  50.             PrintDocument document = (PrintDocument)sender;  
  51.             Graphics g = e.Graphics;  
  52.   
  53.             Brush brush = new SolidBrush(Color.Black);  
  54.             Pen pen = new Pen(brush);  
  55.             Font font = new Font("Arial", 10, FontStyle.Bold);  
  56.             Font fonte = new Font("Arial", 15, FontStyle.Bold);  
  57.             int x = 0, y = 0, width = 200, height = 30;  
  58.   
  59.             SizeF sizeeee = g.MeasureString("TIME :: ", fonte);  
  60.             float xPaddingeee = (width - sizeeee.Width) / 2;  
  61.             g.DrawString("TIME :: ", fonte, brush, x + xPaddingeee, y + 5);  
  62.             x += width;  
  63.   
  64.   
  65.             SizeF sizee = g.MeasureString(DateTime.Now.ToString(), fonte);  
  66.             float xPaddinge = (width - sizee.Width) / 2;  
  67.   
  68.             g.DrawString(DateTime.Now.ToString(), fonte, brush, x + xPaddinge, y + 5);  
  69.             x += width;  
  70.   
  71.             for (int kk = 0; kk < 2; kk++)  
  72.             {  
  73.                 SizeF sizeee = g.MeasureString("", font);  
  74.                 float xPaddingee = (width - sizee.Width) / 2;  
  75.   
  76.                 g.DrawString("", font, brush, x + xPaddingee, y + 5);  
  77.                 x += width;  
  78.             }  
  79.             x = 0;  
  80.             y += 60;  
  81.   
  82.   
  83.             foreach (DataColumn column in dtGetChecked.Columns)  
  84.             {  
  85.                   
  86.                 dtGetChecked.Columns[0].ColumnName = "??? ?????";  
  87.                 dtGetChecked.Columns[1].ColumnName = "????? ?????";  
  88.                 dtGetChecked.Columns[2].ColumnName = "?????";  
  89.                 dtGetChecked.Columns[3].ColumnName = "???? ?????";  
  90.                 //====  
  91.                 g.DrawRectangle(pen, x, y, width, height);  
  92.                 SizeF size = g.MeasureString(column.ColumnName, fonte);  
  93.                 float xPadding = (width - size.Width) / 2;  
  94.                  
  95.                 g.DrawString(column.ColumnName, fonte, brush, x + xPadding, y + 5);  
  96.                 x += width;  
  97.             }  
  98.   
  99.   
  100.             x = 0;  
  101.             y += 30;  
  102.             int columnCount = dtGetChecked.Columns.Count;  
  103.   
  104.              
  105.             foreach (DataRow row in dtGetChecked.Rows)  
  106.             {  
  107.                 for (int i = 0; i < columnCount; i++)  
  108.                 {  
  109.                     g.DrawRectangle(pen, x, y, width, height);  
  110.                     SizeF size = g.MeasureString(row[i].ToString(), font);  
  111.                     float xPadding = (width - size.Width) / 2;  
  112.                     if (i == 3)  
  113.                     {  
  114.                         if (row[i] != System.DBNull.Value)  
  115.                         {  
  116.                             Point loc = new Point(Utilities.ObjectConverter.ConvertToInteger( x + xPadding), y + 5);  
  117.                             //g.DrawImage(byteArrayToImage((byte[])row[i]), x + xPadding, y + 5);  
  118.                             g.DrawImage(byteArrayToImage((byte[])row[i]), new Rectangle(x+60, y , 50, 30));  
  119.                         }  
  120.                          
  121.                     }  
  122.                     else  
  123.                     {  
  124.   
  125.   
  126.                         g.DrawString(row[i].ToString(), font, brush, x + xPadding, y + 5);  
  127.                     }  
  128.                       
  129.                     x += width;  
  130.                 }  
  131.                 x = 0;  
  132.                 y += 30;  
  133.             }  

so please can you help me 

i think before two days and until now not reach how to prevent print ?


Answers (3)