如何在行中自动调整文本的情况下连续打印长名称 [英] How do I print long name in a row with auto adjust text in row

查看:83
本文介绍了如何在行中自动调整文本的情况下连续打印长名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打印发票,其中特殊,HSNCode和单位,批次,Exp等..这些项目在我的发票中,但当特定文本大小像盐酸二甲双胍持续或超过此时它与HSNCode重叠和单位,

如何在特殊栏目中调整文字大小



我尝试了什么:



e.Graphics.DrawString(Particulars,new Font(Arial,15,FontStyle.Regular),Brushes.Black,new Point(35,300) ));



e.Graphics.DrawString(HSNCode,新字体(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));

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:

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));

推荐答案

使用MeasureString



Graphics.MeasureString,méthode(System.D rawing) [ ^ ]



Ex:

Use MeasureString

Graphics.MeasureString, méthode (System.Drawing)[^]

Ex:
private void Form1_Paint(object sender, PaintEventArgs e)
        {
            int columnSize = 100;
            e.Graphics.DrawString("Particulars", new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(35, 300));
           Font font = fitText(e.Graphics, "Metaformin Hydrochloride Sustained", new Font("Arial", 15, FontStyle.Regular), columnSize);
            e.Graphics.DrawString("Metaformin Hydrochloride Sustained", font, Brushes.Black, new Point(35, 350));            
            e.Graphics.DrawString("HSNCode", new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(columnSize*2, 300));
            e.Graphics.DrawString("Unit", new Font("Arial", 15, FontStyle.Regular), Brushes.Black, new Point(columnSize*3, 300));
            e.Graphics.Dispose();
        }

        private Font fitText(Graphics e,string text,Font font,double maxWidth)
        {            
            while (e.MeasureString(text, font).Width > maxWidth)
               font = new Font(font.FontFamily, font.Size - 0.1F,font.Style);

            return font;
        }


这篇关于如何在行中自动调整文本的情况下连续打印长名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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