C#使用字体样式打印
我想打印一些这样的文本 这就是我想打印文本的方式 我使用的代码是C#使用字体样式打印,c#,printing,C#,Printing,我想打印一些这样的文本 这就是我想打印文本的方式 我使用的代码是 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 PrintPageEv
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这将使他的字符串中的所有单词都加粗,这不是他想要的。他的问题一点也不容易。你在打印之前在同一个文件中创建了几个字体样式,成功了吗?不,如果我这样做了,那就不会有问题了!您是否遇到了错误,或者问题是它只是以相同的字体打印所有内容?这可能是一个愚蠢的问题,但既然您已经有了一个表单,为什么不添加一个隐藏的RichTextControl,添加格式化文本,然后打印RichTextControl的内容呢?#Philip。RichtextControl做到了。另一种方法是使用webBrowser的HTML。谢谢