我现在想实现的功能是当form2窗体打开后,不需要提示,直接就打印form2窗体中的全部内容,不知道有什么控件没有,直接添加就可以完成此功能。3我现在是在load事件中写this.PrintForm();但是不对,c#中可以这样写吗??如果不能这么写,该怎么修改下,谢谢!!!!!!!
Bitmap memoryImage = null; //å®ä¹ä¸ä¸ªå¾ç
public static PrintDocument printDocument = new PrintDocument(); //å®ä¹ä¸ä¸ªPrintæ档对象
private void CaptureScreen()//æªå±
{
Form form = this;
if (form != null)
{
Graphics mygraphics = form.CreateGraphics();
memoryImage = new Bitmap(form.Width, form.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
memoryGraphics.CopyFromScreen(form.Location.X, form.Location.Y, 0, 0, form.Size);
}
}
å¨çªä½çloadéé¢åï¼
printDocument.PrintPage += new PrintPageEventHandler(PrintDocument_PrintPage);
printDocument.Print(); //æå°
å ä¸è¿ä¸ªäºä»¶å¤çï¼
void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.Clear(Color.White);
e.Graphics.DrawImage(memoryImage, 0, 0);
}
代ç ç»è¿æµè¯äºãè¥è¿ä¸æç½,Hiææemail:lijiuning(a)gmail.com
public static PrintDocument printDocument = new PrintDocument(); //å®ä¹ä¸ä¸ªPrintæ档对象
private void CaptureScreen()//æªå±
{
Form form = this;
if (form != null)
{
Graphics mygraphics = form.CreateGraphics();
memoryImage = new Bitmap(form.Width, form.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
memoryGraphics.CopyFromScreen(form.Location.X, form.Location.Y, 0, 0, form.Size);
}
}
å¨çªä½çloadéé¢åï¼
printDocument.PrintPage += new PrintPageEventHandler(PrintDocument_PrintPage);
printDocument.Print(); //æå°
å ä¸è¿ä¸ªäºä»¶å¤çï¼
void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.Clear(Color.White);
e.Graphics.DrawImage(memoryImage, 0, 0);
}
代ç ç»è¿æµè¯äºãè¥è¿ä¸æç½,Hiææemail:lijiuning(a)gmail.com
温馨提示:答案为网友推荐,仅供参考
第1个回答 2010-07-20
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Printing;
public class Form1 :
Form
{//实现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());
}
}
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Printing;
public class Form1 :
Form
{//实现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());
}
}
第2个回答 2010-07-20
请使用PrintForm类,它可以直接打印窗体,具体用法请参看msdn