C#打印页面边框 [英] C# Print page borders

查看:203
本文介绍了C#打印页面边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我需要一些帮助.

我有一张要打印在页面上的图像,问题是这样的.
除了图像,我还必须在页面上打印边框.
我试图做的是使用printpageEvents的Graphics方法DrawLine并在由设置的margins()给定的4个点之间绘制四条简单的线,但是我似乎无法在应绘制它们的位置绘制线.整个图像可以左右移动,也可以不用说距页面顶部10mm的顶部边框(线),而是打印15mm ...

有任何想法吗?这让我发疯了!疯了我说!

感谢您的帮助.

I need some help, guys.

I have an image that is to be printed on a page, and the problem is this.
Besides the image, I have to have on the page the borders printed as well.
What i tried to do is use the Graphics method DrawLine of the printpageEvents and draw four simple lines between the 4 points given by the set margins (), but I can''t seem to get the lines drawn where they should be drawn. The whole image is either shifted right and down or instead of let''s say the top border(line) being at 10mm from the top of the page, it''s printed at 15mm...

Any ideas? It''s driving me mad! Mad I Say!!

Thanks for your help.

推荐答案

每台打印机的最小边距设置.可能比打印机的最小尺寸小10mm.

我用Google搜索了"C#打印页边距",并发现了以下内容:

http://msdn.microsoft.com/en-us/library/system. drawing.printing.margins.aspx [ ^ ]
Each printer has a minimum margin setting. Maybe 10mm smaller than your printer''s minumum.

I googled "C# printing margins", and found this:

http://msdn.microsoft.com/en-us/library/system.drawing.printing.margins.aspx[^]


,您可以使用页面的边距边界绘制一个矩形.
e.DrawRectangle(pen.black,e.marginbounds)
you can draw a rectangle using marginbounds of the page.
i.e. e.DrawRectangle(pen.black,e.marginbounds)


public void Printing()
{
尝试
{
/*这假定字符串类型的变量名为filePath,
已设置为要打印的文件的路径. */
streamToPrint =新的StreamReader(filePath);
尝试
{
printFont = new Font("Arial",10);
PrintDocument pd = new PrintDocument();
/*这假定一个名为pd_PrintPage的方法已经
定义. pd_PrintPage处理PrintPage事件. */
pd.PrintPage + =新的PrintPageEventHandler(pd_PrintPage);
/*这假定一个名为
的字符串类型的变量 打印机,已被设置为打印机的名称. */
pd.PrinterSettings.PrinterName =打印机;
//创建一个具有一英寸边距的Margins的新实例.
保证金保证金=新保证金(100,100,100,100);
pd.DefaultPageSettings.Margins =边距;
pd.Print();
}
终于
{
streamToPrint.Close();
}
}
catch(Exception ex)
{
MessageBox.Show(打印文件时发生错误-" + ex.Message);
}
}
public void Printing()
{
try
{
/* This assumes that a variable of type string, named filePath,
has been set to the path of the file to print. */
streamToPrint = new StreamReader (filePath);
try
{
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
/* This assumes that a method, named pd_PrintPage, has been
defined. pd_PrintPage handles the PrintPage event. */
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
/* This assumes that a variable of type string, named
printer, has been set to the printer''s name. */
pd.PrinterSettings.PrinterName = printer;
// Create a new instance of Margins with one inch margins.
Margins margins = new Margins(100,100,100,100);
pd.DefaultPageSettings.Margins = margins;
pd.Print();
}
finally
{
streamToPrint.Close() ;
}
}
catch(Exception ex)
{
MessageBox.Show("An error occurred printing the file - " + ex.Message);
}
}


这篇关于C#打印页面边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆