Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.75/5 (4 votes)
See more:
Give any code its urgent please.

Thanks,
Surender
Posted
Comments
Joezer BH 2-Jul-14 8:09am    
Please elaborate...
Member 10918392 2-Jul-14 8:13am    
I have to write code to print the form directly to the printers without coming any dialog box
[no name] 2-Jul-14 8:20am    
"Gimme code" is not only rude, it's not even a question.
Member 10918392 2-Jul-14 8:24am    
i want to write a program for print option is click at that time it should directly print
no dialogue box will come
now u will uderstand i think
[no name] 2-Jul-14 10:28am    
Okay... and? If you want to write this code then go ahead. No one is going to stop you doing a teeny tiny bit of research and writing the code. Do you have an actual question or some sort of a problem you would like to share with us?

1 solution

Here's a C# example from Microsoft:

This example demonstrates printing a copy of the current form.
C#
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage;
private void CaptureScreen()
{
   Graphics mygraphics = this.CreateGraphics();
   Size s = this.Size;
   memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
   Graphics memoryGraphics = Graphics.FromImage(memoryImage);
   IntPtr dc1 = mygraphics.GetHdc();
   IntPtr dc2 = memoryGraphics.GetHdc();
   BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
   mygraphics.ReleaseHdc(dc1);
   memoryGraphics.ReleaseHdc(dc2);
}
private void printDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
   e.Graphics.DrawImage(memoryImage, 0, 0);
}
private void printButton_Click(System.Object sender, System.EventArgs e)
{
   CaptureScreen();
   printDocument1.Print();
}



Good luck,
C
 
Share this answer
 
Comments
Member 10918392 2-Jul-14 8:19am    
fine but printDocument1 does not exist in current contex is coming
what i have to do in this part
Joezer BH 2-Jul-14 9:14am    
Naturally, this example requires:
#) A PrintDocument component named printDocument1 with a PrintPage event handler.
#) A Button named printButton with a Click event handler.

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