如何给出一个确切大小的表格? [英] how to give a form exact size?

查看:76
本文介绍了如何给出一个确切大小的表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我不是英语用户,请原谅我语法问题。 :)

我有一些纸质表格,我想打印一些标签。这些纸张有特殊尺寸(24厘米* 14)。所以我做了一个面板(907像素* 529像素)和我把标签放在上面(我将cm转换为像素,我将标签放在面板的特殊部位)。这些标签将打印在我的纸张表格的空白区域。但问题是,只是第一种形式可以用正确的样式打印。其他人印在表格的上方。我想这可能是因为我没有给我的面板和标签确切的像素大小。但我不能给我的面板确切的大小,以像素为单位,因为它不接受十进制像素。任何想法?

这是我的代码的一部分:

  private   void  printDocument1_PrintPage( object  sender,System.Drawing.Printing.PrintPageEventArgs e)
{
Pen blackPen = new 笔(Color.Black, 1 );
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
e.Graphics.DrawLine(blackPen, 188 400 302 400 );
e.Graphics.DrawRectangle(blackPen, 330 319 122 55 );
e.Graphics.DrawString(label20.Text,label20.Font, new SolidBrush(label20.ForeColor),label20.Location);
e.Graphics.DrawString(label21.Text,label21.Font, new SolidBrush(label21.ForeColor),label21.Location);
e.Graphics.DrawString(label23.Text,label23.Font, new SolidBrush(label23.ForeColor),label23.Location);
e.Graphics.DrawString(label24.Text,label24.Font, new SolidBrush(label24.ForeColor),label24.Location);
e.Graphics.DrawString(label25.Text,label25.Font, new SolidBrush(label25.ForeColor),label25.Location);
e.Graphics.DrawString(label26.Text,label26.Font, new SolidBrush(label26.ForeColor),label26.Location);
e.Graphics.DrawString(label27.Text,label27.Font, new SolidBrush(label27.ForeColor),label27.Location);
}



和每种纸质表格的打印区域:



 System.Drawing.Printing.PrintDocument doc =  new  System.Drawing.Printing.PrintDocument(); 
doc.PrintPage + = new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
PrintDialog PrintSettings = new PrintDialog();
PrintSettings.Document = doc;
PageSettings pgsetting = new PageSettings();
doc.Print();

解决方案

打印时不应使用像素值,因为它们不一样屏幕值。您应该使用以英寸或毫米为单位定义的实际测量值,如 http://msdn.microsoft.com/en-us/library/system.drawing.printing(v = vs.110).aspx [ ^ ]。请参阅 http://msdn.microsoft。 com / en-us / library / system.drawing.printing.pagesettings.hardmarginx(v = vs.110).aspx [ ^ ],了解如何完成。


使用边距如下:



边距边距=新边距(100,100,100,100);


hi everyone. I'm not an English user,so forgive me for grammatical problems please. :)
I have some paper forms that i want to print some labels on them.these papers have special size(24 cm * 14).so I made a panel(907 pixel * 529 pixel) and i put my labels on it(I converted cm to pixel and i put labels in the special parts of my panel).these labels are going to be printed in empty fields of my paper forms.but the problem is that, just the first form can be printed in the right style.others are printed in upper place of the form. I thought it may be because of I didn't give my panel and labels exact size in pixel. but i couldn't give my panel exact size in pixels,coz it doesn't accept pixels in decimal. any ideas?
this is a part of my code:

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Pen blackPen = new Pen(Color.Black, 1);
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            e.Graphics.DrawLine(blackPen, 188, 400, 302, 400);
            e.Graphics.DrawRectangle(blackPen, 330, 319, 122, 55);
            e.Graphics.DrawString(label20.Text, label20.Font, new SolidBrush(label20.ForeColor), label20.Location);
            e.Graphics.DrawString(label21.Text, label21.Font, new SolidBrush(label21.ForeColor), label21.Location);
            e.Graphics.DrawString(label23.Text, label23.Font, new SolidBrush(label23.ForeColor), label23.Location);
            e.Graphics.DrawString(label24.Text, label24.Font, new SolidBrush(label24.ForeColor), label24.Location);
            e.Graphics.DrawString(label25.Text, label25.Font, new SolidBrush(label25.ForeColor), label25.Location);
            e.Graphics.DrawString(label26.Text, label26.Font, new SolidBrush(label26.ForeColor), label26.Location);
            e.Graphics.DrawString(label27.Text, label27.Font, new SolidBrush(label27.ForeColor), label27.Location);
            }


and the print region for each paper form:

System.Drawing.Printing.PrintDocument doc = new System.Drawing.Printing.PrintDocument();
doc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
PrintDialog PrintSettings = new PrintDialog();
PrintSettings.Document = doc;
PageSettings pgsetting = new PageSettings();
doc.Print();

解决方案

You should not use pixel values when printing, since they are not the same as screen values. You should use actual measurements defined in inches or millimeters, as described in http://msdn.microsoft.com/en-us/library/system.drawing.printing(v=vs.110).aspx[^]. See http://msdn.microsoft.com/en-us/library/system.drawing.printing.pagesettings.hardmarginx(v=vs.110).aspx[^] for a sample of how it is done.


Use the Margins as follows:

Margins margins = new Margins(100,100,100,100);


这篇关于如何给出一个确切大小的表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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