如何使用文本对齐在特定列中打印长特定名称 [英] How do I print long particular name in particular column with text align

查看:125
本文介绍了如何使用文本对齐在特定列中打印长特定名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i want to print invoice in which Particular,HSNCode and Unit, Batch, Exp and so on.. these items are in my invoice but when particular text size is like "Metaformin Hydrochloride Sustained" or more than this it overlap with HSNCode and Unit,
how to adjust text size in a "Particular Column"





我尝试过:





What I have tried:

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
       {
           Image image = Resources.ppreview;
           e.Graphics.DrawImage(image, 0, 0, image.Width, image.Height);

           Image img = Resources.printlogo2;
           e.Graphics.DrawImage(img, 510, 01, image.Width, image.Height);




           e.Graphics.DrawString("Name: " + textBox2.Text.Trim(), new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(35, 220));

           e.Graphics.DrawString("Mobile No : " + textBox3.Text, new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(35, 250));
           //Bill
           e.Graphics.DrawString("Bill No : " + textBox14.Text, new Font("Arial", 15, FontStyle.Bold), Brushes.Black, new Point(510, 220));
           //Date
           e.Graphics.DrawString("Date : " + DateTime.Now, new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(510, 250));
           //Line
           e.Graphics.DrawString("-------------------------------------------------------------------------------------------------------------- ", new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(35, 280));
           //Details
           e.Graphics.DrawString("Particulars", new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(35, 300));
           e.Graphics.DrawString("HSNCode", new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(250, 300));
           e.Graphics.DrawString("Unit", new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(390, 300));
           e.Graphics.DrawString("Batch", new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(450, 300));
           e.Graphics.DrawString("Qty", new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(520, 300));
           e.Graphics.DrawString("Exp.", new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(570, 300));
           e.Graphics.DrawString("Rate", new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(645, 300));
           e.Graphics.DrawString("Amount", new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(720, 300));
           //Line
           e.Graphics.DrawString("-------------------------------------------------------------------------------------------------------------- ", new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(35, 320));

           int yPos = 350;
           foreach (var i in Product)
           {
               e.Graphics.DrawString(i.Particular, new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(35, yPos));

               e.Graphics.DrawString(i.HSNCode, new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(270, yPos));

               e.Graphics.DrawString(i.Unit, new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(400, yPos));

               e.Graphics.DrawString(i.Batch, new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(470, yPos));

               e.Graphics.DrawString(i.Qty, new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(525, yPos));

               e.Graphics.DrawString(i.Exp, new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(560, yPos));

               e.Graphics.DrawString(i.Rate, new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(650, yPos));

               e.Graphics.DrawString(i.Amount.ToString(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(730, yPos));

               yPos += 30;
           }
           e.Graphics.DrawString("-------------------------------------------------------------------------------------------------------------- ", new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(35, yPos));
           e.Graphics.DrawString("SubTotal      : " + textBox1.Text.Trim(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(600,yPos+30));

           e.Graphics.DrawString("Total to Pay  : " + textBox11.Text.Trim(), new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(600, yPos + 90));



       }

推荐答案

这似乎是一种尴尬的方式'打印'某事......我会说你应该学习如何从代码中创建PDF ...

在任何情况下,DrawString都有一个写在矩形内的版本,所以你可以设置文本的边框并且它不会流过它的邻居......但是会被切断......

Graphics.DrawString方法(String,Font,Brush,RectangleF)(System.Drawing) [ ^ ]
It seems to be an awkward way to 'print' something... I would say you should learn about creating PDF from your code...
In any case DrawString has version that writes inside a rectangle, so you can set the border for your text and it will not flow over its neighbors... but will be cut...
Graphics.DrawString Method (String, Font, Brush, RectangleF) (System.Drawing)[^]


您已经得到了答案在 https:// www .codeproject.com / Questions / 1249927 /如何使用自动调整的方法来打印长名称[ ^ ]。请不要重新发布相同的问题。
You have already been given an answer at https://www.codeproject.com/Questions/1249927/How-do-I-print-long-name-in-a-row-with-auto-adjust[^]. Please do not repost the same question.


这篇关于如何使用文本对齐在特定列中打印长特定名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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