首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C# 自定义打印纸张大小,该如何处理

2012-05-20 
C# 自定义打印纸张大小我是在printDocument1_PrintPage事件里用e.Graphics.DrawString来打印字符串form中

C# 自定义打印纸张大小
我是在printDocument1_PrintPage事件里
用e.Graphics.DrawString来打印字符串
form中设置一个按钮,单击按钮的时候

C# code
   PrintDialog printDialog = new PrintDialog();            printDialog.Document = this.printDocument1;            printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Default", 315, 394);            if (printDialog.ShowDialog() == DialogResult.OK)            {                try                {                    printDocument1.Print();                }                catch (Exception excep)                {                    MessageBox.Show(excep.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error);                }            }

我应该在添加什么代码使之可以按照8cm*10cm的尺寸打印?
谢谢了。
我自己找了“printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Default", 315, 394);”这一句代码,但是使用无效,操作系统为win XP or 2003

[解决办法]
哥们,我刚才试了一下 你用微软自带的打印机调试下,有啥不明白你再回帖吧
C# code
 private void button1_Click(object sender, EventArgs e)        {            if (printDialog1.ShowDialog() == DialogResult.OK)            {                try                {                    printDocument1.PrintPage +=new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);                    printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Default", 200, 150);                    printDocument1.Print();                }                finally                { }            }        }        private void printDocument1_PrintPage(object sender, PrintPageEventArgs ev)        {            ev.Graphics.DrawString("haha", new Font("宋体", 10), Brushes.Black, new PointF(10, 10));        }
[解决办法]
LZ加我Q453367672

我有demo,源码献上

热点排行