请问关于printdocument打印的有关问题
请教关于printdocument打印的问题
请教下 printdocument
可以直接绘制 窗体的控件吗 不用用印屏幕的方式
因为我控件是根据数值自动增加的
------解决方案--------------------
读窗体大小画窗体及其Text等属性
遍历窗体所有控件,画控件及其Text等属性
------解决方案--------------------
------解决方案--------------------
跑到一行了,改成
------解决方案--------------------
打印控件?
可以把上面代码改下,把打印相关的改在控件里,动态加载控件后,打印这些控件就可以了
参看下面代码,另外印屏幕有什么不好?
请教下 printdocument
可以直接绘制 窗体的控件吗 不用用印屏幕的方式
因为我控件是根据数值自动增加的
------解决方案--------------------
读窗体大小画窗体及其Text等属性
遍历窗体所有控件,画控件及其Text等属性
------解决方案--------------------
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());
}
}
------解决方案--------------------
//实现C#打印窗体 public static void Main()
跑到一行了,改成
//实现C#打印窗体
public static void Main()
------解决方案--------------------
打印控件?
可以把上面代码改下,把打印相关的改在控件里,动态加载控件后,打印这些控件就可以了
参看下面代码,另外印屏幕有什么不好?
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Printing;
public class Form1 : Form
{
//实现C#打印窗体
private Button printButton = new Button();
//动态创建的可以打印控件
private PrintControl printControl = new PrintControl();
public Form1()
{
this.Size = new System.Drawing.Size(500, 400);