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

  • Thread starter Thread starter engahmedbarbary
  • Start date Start date
E

engahmedbarbary

Guest
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 ?

datatable get checked

public DataTable GetChecked()
{
DataTable table = new DataTable();
table.Columns.Add("MemberCode", typeof(string));

table.Columns.Add("SpecialCode", typeof(string));

table.Columns.Add("Name", typeof(string));

table.Columns.Add("MemberImage", typeof(Byte[]));


for (int i = 0; i < dtDisplayDataPayment.Rows.Count; i++)
{

bool Ischecked = Convert.ToBoolean(GridFooter.Rows.Cells["PrintFlag"].Value);
if (Ischecked == true)
{
DataRow newRow = table.NewRow();
newRow["MemberCode"] = Utilities.ObjectConverter.ConvertToString(dtDisplayDataPayment.Rows["MemberCode"]);
newRow["SpecialCode"] = Utilities.ObjectConverter.ConvertToString(dtDisplayDataPayment.Rows["SpecialCode"]);
newRow["Name"] = Utilities.ObjectConverter.ConvertToString(dtDisplayDataPayment.Rows["Name"]);


if (dtDisplayDataPayment.Rows["MemberImage"] != System.DBNull.Value)
{
byte[] photo_aray = (byte[])dtDisplayDataPayment.Rows["MemberImage"];
System.Drawing.ImageConverter converter = new System.Drawing.ImageConverter();
Image img = (Image)converter.ConvertFrom(photo_aray);
newRow["MemberImage"] = imageToByteArray(img);


}


table.Rows.Add(newRow);
}
}

return table;


}




void document_PrintPage(object sender, PrintPageEventArgs e)
{
dtGetChecked = GetChecked();
PrintDocument document = (PrintDocument)sender;
Graphics g = e.Graphics;

Brush brush = new SolidBrush(Color.Black);
Pen pen = new Pen(brush);
Font font = new Font("Arial", 10, FontStyle.Bold);
Font fonte = new Font("Arial", 15, FontStyle.Bold);
int x = 0, y = 0, width = 200, height = 30;

SizeF sizeeee = g.MeasureString("TIME :: ", fonte);
float xPaddingeee = (width - sizeeee.Width) / 2;
g.DrawString("TIME :: ", fonte, brush, x + xPaddingeee, y + 5);
x += width;


SizeF sizee = g.MeasureString(DateTime.Now.ToString(), fonte);
float xPaddinge = (width - sizee.Width) / 2;

g.DrawString(DateTime.Now.ToString(), fonte, brush, x + xPaddinge, y + 5);
x += width;

for (int kk = 0; kk < 2; kk++)
{
SizeF sizeee = g.MeasureString("", font);
float xPaddingee = (width - sizee.Width) / 2;

g.DrawString("", font, brush, x + xPaddingee, y + 5);
x += width;
}
x = 0;
y += 60;


foreach (DataColumn column in dtGetChecked.Columns)
{

dtGetChecked.Columns[0].ColumnName = "كود العضو";
dtGetChecked.Columns[1].ColumnName = "الكود الخاص";
dtGetChecked.Columns[2].ColumnName = "الاسم";
dtGetChecked.Columns[3].ColumnName = "صوره شخصيه";
//====
g.DrawRectangle(pen, x, y, width, height);
SizeF size = g.MeasureString(column.ColumnName, fonte);
float xPadding = (width - size.Width) / 2;

g.DrawString(column.ColumnName, fonte, brush, x + xPadding, y + 5);
x += width;
}


x = 0;
y += 30;
int columnCount = dtGetChecked.Columns.Count;


foreach (DataRow row in dtGetChecked.Rows)
{
for (int i = 0; i < columnCount; i++)
{
g.DrawRectangle(pen, x, y, width, height);
SizeF size = g.MeasureString(row.ToString(), font);
float xPadding = (width - size.Width) / 2;
if (i == 3)
{
if (row != System.DBNull.Value)
{
Point loc = new Point(Utilities.ObjectConverter.ConvertToInteger( x + xPadding), y + 5);
//g.DrawImage(byteArrayToImage((byte[])row), x + xPadding, y + 5);
g.DrawImage(byteArrayToImage((byte[])row), new Rectangle(x+60, y , 50, 30));
}

}
else
{


g.DrawString(row.ToString(), font, brush, x + xPadding, y + 5);
}

x += width;
}
x = 0;
y += 30;
}



code using for button print preview

private void PrintPreview_Click(object sender, EventArgs e)
{

PrintDocument document = new PrintDocument();
PrintController printController = new StandardPrintController();
document.PrintController = printController;
document.PrintPage += new PrintPageEventHandler(document_PrintPage);



PrintPreviewDialog ppDialog = new PrintPreviewDialog();

((ToolStripButton)((ToolStrip)ppDialog.Controls[1]).Items[0]).Enabled = false;
ppDialog.Document = document;
ppDialog.Show();




}

so please can you help me

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

Continue reading...
 
Back
Top