我在c#winform中添加了一些labels
和textboxes
,我想用我设置的布局打印该表单。
我试过这个
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(this.Jumbo_Load);
PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = pd;
ppd.ShowDialog();
但这只是打开一个空白页面。不是我想要的那个。
如果有人可以帮助我,那将非常感激。
另外,我创建了SAP Crystal Report。如果有人可以告诉我如何使用查询过滤某些记录。因为那时,我可以打印那份报告。
答案 0 :(得分:0)
我不确定您是否有更多代码,但我有类似情况,如下所示:
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(this.Jumbo_Load);
PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = pd;
DialogResult result = ppd.ShowDialog();
if (result == DialogResult.OK) {
pd.Print();
}
答案 1 :(得分:0)
来自MSDN
[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();
}