C#使用字体样式打印
本文关键字:样式 式打印 字体 | 更新日期: 2023-09-27 18:28:13
我想打印一些这样的文本。
这就是我希望打印文本的方式。
我使用的代码是
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);
}
我想将字体从常规更改为粗体,或者为字符串中的某些特定单词加下划线。
如果有其他更好的方法来完成这项工作,请告诉我我会更改代码。请帮帮我!:)
您可以尝试:
printFont = new Font("Arial", 24,FontStyle.Bold);
ThangNguyen