C#如何实现打印居中

来源:互联网 发布:ant编译java项目 编辑:程序博客网 时间:2024/05/20 03:46

//实现横向居中

PrintPageEventArgs e;            

StringFormat SF = new StringFormat();
SF.LineAlignment = StringAlignment.Center;                                        //设置属性为水平居中
SF.Alignment = StringAlignment.Center;                                               //设置属性为垂直居中
 RectangleF rect = new RectangleF(0,0,e.PageBounds.Width,e.Graphics.MeasureString("Authors Informations",new Font("Times New Roman",20)).Height);    //其中e.PageBounds属性表示页面全部区域的矩形区域

e.Graphics.MeasureString(string,Font).Height

//表示获取你要打印字符串的高度

 e.Graphics.DrawString("Authors Informations",new Font("Times New Roman",20),Brushes.Black,rect,SF);