private void button1_Click(object sender, EventArgs e)
{
//打印
printDocument1.Print();
}
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
Font titleFont = new Font("新宋体", 10, FontStyle.Bold);//字体
Brush brush = new SolidBrush(Color.Black);//画刷
Point po = new Point(10, 10); //坐标
float left = e.PageSettings.Margins.Left;//打印区域的左边界
float top = e.PageSettings.Margins.Top;//打印区域的上边界
float width = e.PageSettings.PaperSize.Width - left - e.PageSettings.Margins.Right;//计算出有效打印区域的宽度
float height = e.PageSettings.PaperSize.Height - top - e.PageSettings.Margins.Bottom;//计算出有效打印区域的高度
int wid = e.PageSettings.PaperSize.Width;
//标题
string name = "99街区KTV";
//这里想要居中打印标题
e.Graphics.DrawString(name, titleFont, brush, 80 - name.Length + 2, 80 - name.Length + 2);
}
以上是我的代码、我想要标题居中打印、用的是 printDocument控件 10 号字体、80mm热敏纸、printDocument怎么样获取纸宽等等、主要标题居中这个算法怎么做呢?有没有大神做过、能给个例子吗?求帮助、在线等