C# Printing with Font Styles

陌路散爱 提交于 2020-01-16 04:49:05

问题


I want to print some text like this.

This is how i want to print the text.

the code i am using is

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! :)


回答1:


You can try:

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

ThangNguyen



来源:https://stackoverflow.com/questions/18308324/c-sharp-printing-with-font-styles

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!