如何在C#中为面板提供确切的尺寸?

纳齐拉

我不是英语用户,所以请原谅我的语法问题。微笑 :)我有一些纸质表格要在上面打印一些标签。这些纸张具有特殊的尺寸(24厘米* 14)。所以我做了一个面板(907像素* 529像素),并在上面贴了标签(我将cm转换为像素,然后将标签放在面板的特殊部分中)。这些标签将被打印在纸质表格的空白区域中,但问题在于,只有第一个表格可以正确的样式打印。其他的则打印在表格的上方。我认为可能是因为我没有给面板和标签提供像素的确切大小。但是我不能给我的面板精确的像素大小,因为它不接受十进制的像素。有任何想法吗?这是我的代码的一部分:

    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);
e.Graphics.DrawString(lbl_kod.Text, lbl_kod.Font, new SolidBrush(lbl_kod.ForeColor), lbl_kod.Location);
            e.Graphics.DrawString(lbl_ttarikh.Text, lbl_ttarikh.Font, new SolidBrush(lbl_ttarikh.ForeColor), lbl_ttarikh.Location);
            e.Graphics.DrawString(lbl_ctot25.Text, lbl_ctot25.Font, new SolidBrush(lbl_ctot25.ForeColor), lbl_ctot25.Location);
            e.Graphics.DrawString(lbl_pricetot25.Text, lbl_pricetot25.Font, new SolidBrush(lbl_pricetot25.ForeColor), lbl_pricetot25.Location);
            e.Graphics.DrawString(lbl_pricetot.Text, lbl_pricetot.Font, new SolidBrush(lbl_pricetot.ForeColor), lbl_pricetot.Location);
            e.Graphics.DrawString(lbl_pricetoth.Text, lbl_pricetoth.Font, new SolidBrush(lbl_pricetoth.ForeColor), lbl_pricetoth.Location);
            e.Graphics.DrawString(lbl_name.Text, lbl_name.Font, new SolidBrush(lbl_name.ForeColor), lbl_name.Location);
            e.Graphics.DrawString(lbl_dtarikh.Text, lbl_dtarikh.Font, new SolidBrush(lbl_dtarikh.ForeColor), lbl_dtarikh.Location);        

            }

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

for (int i = 0; i < dataGridView1.RowCount && k < 3878; i++)
            {
                k = Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value);
                bool found = false;
                ctot25 = Convert.ToInt32(dataGridView1.Rows[i].Cells[13].Value);
                ctot50 = Convert.ToInt32(dataGridView1.Rows[i].Cells[14].Value);
                ctot100 = Convert.ToInt32(dataGridView1.Rows[i].Cells[15].Value);
                foreach (object row1 in hoome)
                    if (row1.ToString() == (dataGridView1.Rows[i].Cells[0].Value).ToString())
                    {
                        found = true;
                    }

                if (found == false)
                {
                    if (i > 0 && ctot25 != 0 || ctot50 != 0 || ctot100 != 0)
                    {
                        #region tarikh
                        string date = dataGridView1.Rows[i].Cells[8].Value.ToString();
                        var aStringBuilder = new StringBuilder(date);
                        aStringBuilder.Insert(2, "/");
                        aStringBuilder.Insert(5, "/");
                        lbl_dtarikh.Text = aStringBuilder.ToString();

                        lbl_ttarikh.Text = datestringbuilder.ToString();
                        #endregion

                        decimal pricetot25;
                        pricetot25 = ctot25 * price25;
                        lbl_name.Text = (dataGridView1.Rows[i].Cells[1].Value).ToString();
                        lbl_kod.Text = (dataGridView1.Rows[i].Cells[0].Value).ToString();
                        lbl_ctot25.Text = (ctot25).ToString();
                        lbl_pricetot25.Text = (pricetot25).ToString();
                        lbl_pricetoth.Text = num2str(pricetot.ToString()) + " ریال" + "//";

                        #region print
                        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();
                        #endregion
                    }
                }
            }

这是我的屏幕截图的链接:我的面板

亚历克斯·乔利格

由于您的问题尚不清楚,我认为您最好不要在设计布局中添加面板并以编程方式创建它。如果您对第二页进行屏幕截图,那会更好。

编辑:

尝试在FOR循环中创建标签。您可以通过这种方式放置面板。我希望它能起作用

 if (found == false)
                {
                    if (i > 0 && ctot25 != 0 || ctot50 != 0 || ctot100 != 0)
                    {
                        //Somthethin

                        Label lbl_Name = new Label { Location = new Point(50, 50), Text = (dataGridView1.Rows[i].Cells[1].Value).ToString() };
                         this.Controls.Add(lbl_Name);

                         //The rest of the codes

                    }
                }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在C#中使用Open XML从Word文档中查找确切的单词?

如何在C#中从cosmos db获取确切的最新5分钟数据

在C#中找出确切的文件类型

如何在python中获取确切的float值?

如何在python中查找确切的根(立方)

如何在Android中获取确切的TimeAgo

如何在Makefile中记录确切的配方行

如何在setTimeout函数中获取确切的值

如何在大邮件中搜索确切的单词?

如何在xpath中获取确切的img src

如何在SQL中获得确切的年份差异

如何在c ++ 11中使用正则表达式找到确切的子字符串?

JPanel确切的图纸尺寸/限制?

与SQL Server的连接失败(C#)时,如何确定确切的异常?

C#代码在Windows文件夹中搜索确切的文件名

如何在Java中仅找到确切的模式匹配?

如何在Excel中创建EXTRA确切的列宽?

如何在javascript中获取确切的媒体查询值?

如何在RecyclerView中显示确切的项目数?

如何在Ruby on Rails中按确切的创建时间排序

如何在浏览器中检索确切的HTML

我如何在laravel中获得确切的错误位置

如何在引号之间的字符串中匹配确切的字符串

如何在MySQL中搜索确切的字符串值?

如何在Angular2中导航到确切的URL字符串

如何在检测习语中要求确切的功能签名?

如何在Excel 2016中设置确切的图表区域大小?

如何在Matplotlib Python中设置确切的日期刻度

如何在Zeplin中修复间距特征”,它显示:“ NaNpx”而不是确切的px值