C# 打印字体样式 [英] C# Printing with Font Styles

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

问题描述

我想打印一些这样的文字.

I want to print some text like this.

这是我如何打印文本.

我使用的代码是

private void button3_Click(object sender, EventArgs e)
    {
        stringToPrint = "This is how i want to print the text";
        printFont = new Font("Times New Roman", 10);
        pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
        try
        {
            pd.Print();
        }
        catch (Exception e)
        {
        }
    }

void pd_PrintPage(object sender, PrintPageEventArgs ev)
    {
        int charactersOnPage = 0;
        int linesPerPage = 0;

        ev.Graphics.MeasureString(stringToPrint, printFont,
            ev.MarginBounds.Size, StringFormat.GenericTypographic,
            out charactersOnPage, out linesPerPage);

        ev.Graphics.DrawString(stringToPrint, printFont, Brushes.Black,
            ev.MarginBounds, StringFormat.GenericTypographic);

        stringToPrint = stringToPrint.Substring(charactersOnPage);

        ev.HasMorePages = (stringToPrint.Length > 0);

    }

我想将字体从常规更改为粗体,或者为字符串中的某些特定单词添加下划线.

I want to change the Font from regular to bold or give an Underline for some specific words in the string.

如果有另一种更好的方法来完成这项工作,请告诉我我会更改我的代码.请帮帮我!:)

And if there is another Better way to do this job then please tell me i'll change my code. Please Help me Out! :)

推荐答案

你可以试试:

  printFont  = new Font("Arial", 24,FontStyle.Bold);

唐阮

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

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