Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I wanna a form to print when i click on print button,for that I'm using printform component but it showing me a to select a file like when we upload something.

how can i do this
Posted

1 solution

private void ButtonPrintClick(object sender, EventArgs e)
{
// Create document
PrintDocument _document = new PrintDocument();
// Add print handler
_document.PrintPage += new PrintPageEventHandler(Document_PrintPage);
// Create the dialog to display results
PrintPreviewDialog _dlg = new PrintPreviewDialog();
_dlg.ClientSize = new System.Drawing.Size(Width / 2, Height / 2);
_dlg.Location = new System.Drawing.Point(Left, Top);
_dlg.MinimumSize = new System.Drawing.Size(375, 250);
_dlg.UseAntiAlias = true;
// Setting up our document
_dlg.Document = _document;
// Show it
_dlg.ShowDialog(this);
// Dispose document
_document.Dispose();
}
// Print handler
private void Document_PrintPage(object sender, PrintPageEventArgs e)
{
// Create Bitmap according form size
Bitmap _bitmap = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
// Draw from into Bitmap DC
this.DrawToBitmap(_bitmap, this.DisplayRectangle);
// Draw Bitmap into Printer DC
e.Graphics.DrawImage(_bitmap,0,0);
// No longer deeded - dispose it
_bitmap.Dispose();
}

Try this and let me know
 
Share this answer
 
Comments
Usha Sanjee 8-Oct-13 1:30am    
its working but I'm using Foxit reader for virtual printer it is showing me same as i said above
it shows me a print preview when i click on print it shows me a pop up
Page 1 of document and a cancel button at the same time a window to select file which as like upload or attach files
Shubh Agrahari 8-Oct-13 1:55am    
so what you actually want...where Print dialogue box find the document that it need to print...explain your need that can help us to help.....
Usha Sanjee 8-Oct-13 2:58am    
And also i noticed from the code you have posted it showing me print preview when i press on print button it should show me the page view(how many copies i need page size etc...)but it not showing me that

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