C# PrintDocument 标题打印问题
主要用于打印小票、在80mm的热敏纸上、用printDocument控件操作上面是打印代码图片、我想让标题居中、这个算法要怎么算呢?求帮助、下面是代码:privatevo...
主要用于打印小票、在 80mm的热敏纸上、用printDocument控件操作
上面是打印代码图片、我想让标题居中、这个算法要怎么算呢?求帮助、下面是代码:
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, width - name.Length + 2, width - name.Length + 2);
} 展开
上面是打印代码图片、我想让标题居中、这个算法要怎么算呢?求帮助、下面是代码:
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, width - name.Length + 2, width - name.Length + 2);
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询