c#中如何打印窗体
我现在想实现的功能是当form2窗体打开后,不需要提示,直接就打印form2窗体中的全部内容,不知道有什么控件没有,直接添加就可以完成此功能。3我现在是在load事件中写...
我现在想实现的功能是当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
展开全部
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());
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
请使用PrintForm类,它可以直接打印窗体,具体用法请参看msdn
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询