一之半解,以为PageSetting能解决横纵向的问题
printdocument.DefaultPageSettings.Landscape = true;//横向printdocument.DefaultPageSettings.Landscape = false;//纵向
其实这只是一个进纸方向,相当于尺寸变了,A4纵向尺寸是210*297,横向尺寸是297*210。当然如果真希望这样的话,上面的代码似乎是无效的,需要在一个事件里设置
printdocument.QueryPageSettings += new QueryPageSettingsEventHandler(printdocument_QueryPageSettings);
事件里设置为横向
void printdocument_QueryPageSettings(object sender, QueryPageSettingsEventArgs e){ e.PageSettings.Landscape = true;//横向}
好了,只好在打印的方法想办法了。
方法一:通过DrawString指定字符排列方式
private void printdocument_printpage(object sender, System.Drawing.Printing.PrintPageEventArgs e){ System.Drawing.Font drawFont = new System.Drawing.Font("宋体", 16); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); float tx = 50.0f; float ty = 125.0f; System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(StringFormatFlags.DirectionVertical); e.Graphics.DrawString("Go to see movie,very good move!", drawFont, drawBrush, tx, ty, drawFormat); e.Graphics.DrawString("大家一起来看电影,电影好好看呀!", drawFont, drawBrush, tx + 30, ty, drawFormat); return;}
我打印了一行中文,一行英文,打印的效果如下图
我希望中文也象英文一样,只好使用下面的方法。
方法二:翻转
private void printdocument_printpage(object sender, System.Drawing.Printing.PrintPageEventArgs e){ System.Drawing.Font drawFont = new System.Drawing.Font("宋体", 16); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); float tx = 50.0f; float ty = 125.0f; e.Graphics.RotateTransform(270); tx = -350.0f; ty = 125.0f; e.Graphics.DrawString("Go to see movie,very good move!", drawFont, drawBrush, tx, ty); e.Graphics.DrawString("大家一起来看电影,电影好好看呀!", drawFont, drawBrush, tx, ty+30); for (int i = 0; i < 15; i++) { float curX = -400 + i * 50; e.Graphics.DrawString(curX.ToString(), drawFont, drawBrush, curX, 20); } return;}
为了更好理解翻转后的坐标系,我加入了15次的X的坐标位置的打印,效果如下:
至于为什么翻转270度,大家可以试试修改度数为1打印一次,再改为45再打印一次。心里就明亮了。