C#如何在tab控件中打印特定的tabpage内容? [英] C# how to print a particular tabpage content in tab control?

查看:90
本文介绍了C#如何在tab控件中打印特定的tabpage内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我创建了一个订购系统,收据位于标签控件的第二个标签中。我想知道如何用按钮收到收据。我试图搜索但没有运气。我只是新的请耐心等待我。如果有人帮忙的话会很棒。谢谢。



我尝试了什么:



我试过:

private void printDocument1_PrintPage(object sender,System.Drawing.Printing.PrintPageEventArgs e)

{

e.Graphics.DrawImage(bmp,0 ,0);

}



位图bmp;



private void button2_Click(object sender,EventArgs e)

{

Graphics g = this.CreateGraphics();

bmp = new Bitmap(this.Size .Width,this.Size.Height,g);

图形mg = Graphics.FromImage(bmp);

mg.CopyFromScreen(this.Location.X,this。 Location.Y,0,0,this.Size);

printPreviewDialog1.ShowDialog();

}



但它打印整个系统设计。我不知道在这里要改变什么。我知道它有点傻。

Hey, Im creating an ordering system and the receipt is located at the second tab in tab control. I want to know how to orint that receipt with button.I tried to search but no luck.Im just new please bear with me. It would be great if someone help. Thank you.

What I have tried:

I tried:
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(bmp, 0, 0);
}

Bitmap bmp;

private void button2_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
bmp = new Bitmap(this.Size.Width, this.Size.Height, g);
Graphics mg = Graphics.FromImage(bmp);
mg.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, this.Size);
printPreviewDialog1.ShowDialog();
}

But it prints the whole system design. I dont know what to change here. I know its kinda silly.

推荐答案

当你想要一小部分时,不要试图打印屏幕图像:它无论如何都无法在所有系统上运行,好像用户在他的系统中全局更改应用程序的大小或字体大小(他们这样做,我的桌面运行100%字体,WookieTab运行150%,因为它的屏幕具有更高的DPI计数)然后大小打印的位图(以及打印尺寸)或打印的实际数据会发生变化。

相反,请使用PrintDocument类,并使用DrawString打印收据,使其与输出纸张匹配 - 标准文章显示了一个示例: PrintDocument Class(System .Drawing.Printing) [ ^ ]
Don't try to print screen images when you want a small bit of it: it is not going to work on all systems anyway, as if the user changes the size of the application or the size of fonts globally in his system (and they do, my desktop runs 100% fonts, the WookieTab runs 150% as it's screen had a higher DPI count) then the size of the bitmap (and hence size of the print) or the actual data printed will change.
Instead, use the PrintDocument class you are, and use DrawString to print the receipt exactly so it matches the output paper - the standard article shows an example: PrintDocument Class (System.Drawing.Printing)[^]


这篇关于C#如何在tab控件中打印特定的tabpage内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆