C# 怎么打印label和textBox的内容

来源:百度知道 编辑:UC知道 时间:2024/05/18 10:33:20
我想做一个只打印label或textBox的程序,用buttn控制,请那位高手大哥\大姐帮帮我!谢谢!

private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics g = e.Graphics; //获得绘图对象
float linesPerPage = 0; //页面的行号
float yPosition = 0; //绘制字符串的纵向位置
float xPosition = 0;
int count = 0; //行计数器
float leftMargin = e.MarginBounds.Left; //左边距
float topMargin = e.MarginBounds.Top; //上边距
string line = null; //行字符串
Font printFont = this.textBoxf1.Font; //当前的打印字体
SolidBrush myBrush = new SolidBrush(Color.Black);//刷子
linesPerPage = e.MarginBounds.Height / printFont.GetHeight(g);//每页可打印的行数
//逐行的循环打印一页
while (count < linesPerPage && ((line = s1.ReadLine()) != null))
{
yPosition = topMargin + (count * printFont.GetHeight(g))-35 ;
xPosition = leftMargin + (count * printFont.Ge