日期:2014-05-17  浏览次数:20411 次

c#窗口打印
各位大師,有對c# winform程序 打印熟悉的嗎?
我希望可以直接打印窗口,而不想另外生產報表再來打印,並可以設置橫堅向的打印方式.

------解决方案--------------------
{//实现C#打印窗体 private Button printButton = new Button(); private PrintDocument printDocument1 = new PrintDocument(); public Form1() { printButton.Text = "Print Form"; printButton.Click += new EventHandler(printButton_Click); printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage); this.Controls.Add(printButton); } void printButton_Click(object sender, EventArgs e) { CaptureScreen(); printDocument1.Print(); } //实现C#打印窗体 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); memoryGraphics.CopyFromScreen( this.Location.X, this.Location.Y, 0, 0, s); } private void printDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.Graphics.DrawImage(memoryImage, 0, 0); } //实现C#打印窗体 public static void Main() { Application.Run(new Form1()); } }
------解决方案--------------------
http://developer.51cto.com/art/200908/146909.htm
------解决方案--------------------
C# code
   1. using System;   
2. using System.Windows.Forms; 
3. using System.Drawing; 
4. using System.Drawing.Printing; 
5. 
6. public class Form1 : 
7.  Form 
8. {//实现C#打印窗体 
9. private Button printButton = new Button(); 
10. private PrintDocument printDocument1 = new PrintDocument(); 
11. 
12. public Form1() 
13.  { 
14.  printButton.Text = "Print Form"; 
15.  printButton.Click += new EventHandler(printButton_Click); 
16.  printDocument1.PrintPage += 
17. new PrintPageEventHandler(printDocument1_PrintPage); 
18. this.Controls.Add(printButton); 
19.  } 
20. 
21. void printButton_Click(object sender, EventArgs e) 
22.  { 
23.  CaptureScreen(); 
24.  printDocument1.Print(); 
25.  } 
26. //实现C#打印窗体 
27.  Bitmap memoryImage; 
28. 
29. private void CaptureScreen() 
30.  { 
31.  Graphics myGraphics = this.CreateGraphics(); 
32.  Size s = this.Size; 
33.  memoryImage = new Bitmap(s.Width, s.Height, myGraphics); 
34.  Graphics memoryGraphics = Graphics.FromImage(memoryImage); 
35.  memoryGraphics.CopyFromScreen( 
36. this.Location.X, this.Location.Y, 0, 0, s); 
37.  } 
38. 
39. private void printDocument1_PrintPage(System.Object sender, 
40. System.Drawing.Printing.PrintPageEventArgs e) 
41.  { 
42.  e.Graphics.DrawImage(memoryImage, 0, 0); 
43.  } 
44. 
45.  //实现C#打印窗体 
46. 
47. public static void Main() 
48.  { 
49.  Application.Run(new Form1()); 
50.  } 
51. } 


------解决方案--------------------
探讨

C# code
1. using System;
2. using System.Windows.Forms;
3. using System.Drawing;
4. using System.Drawing.Printing;
5.
6. public class Form1 :
7. Form