在C#Windows应用程序中使用通用/文本打印机更改字体 [英] Changing Font with Generic/Text Printer in C# Windows Application
问题描述
我想在C#Windows应用程序中打印文本.
为此,我安装了通用/文本打印机.
在C Sharp Code中,我写为:
I want text printing in C# Windows Application.
For this I installed a Generic/Text Printer.
in C Sharp Code I have written as :
string dwon,dwof;
StreamReader streamToPrint;
Font printFont;
dwon = string.Format("{0}{1}", Convert.ToChar(27), Convert.ToChar(69));
dwof = string.Format("{0}{1}", Convert.ToChar(27), Convert.ToChar(70));
StreamWriter sw = new StreamWriter(@"G:\TEST.TXT");
sw.WriteLine(dwon+"Manoj Dua"+dwof);
sw.WriteLine("Gandhi Colony");
sw.WriteLine("Muzaffarnagar");
sw.Close();
try
{
streamToPrint = new StreamReader(@"G:\Test.txt");
try
{
printFont = new Font("Courier", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler
(this.pd_PrintPage);
pd.Print();
}
finally
{
streamToPrint.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
但是Manoj Kumar并未以粗体显示.
在Manoj Kumar之前打印E,在Manoj Kumar之后打印F
错误在哪里,请告诉我.
请帮助
But Manoj Kumar is not printed in bold.
It prints E before Manoj Kumar and F after Manoj Kumar
Where is Mistake, Please tell me.
Please Help
推荐答案
dwon = string.Format("{0}{1}", Convert.ToChar(27), Convert.ToChar(69));
dwof = string.Format("{0}{1}", Convert.ToChar(27), Convert.ToChar(70));
因为Char 69是E而Char 70是F.
string.format重载,您说的是ESC,然后将E放入dwon,将ESC和F放入dwof.
然后将其打印出来,您未指定要粗体显示任何文本.
Because Char 69 is an E and Char 70 is an F.
The string.format is overloaded and you are saying Put in an ESC then an E to dwon and an ESC and an F to dwof.
That is then being printed, you are not specifying that you want to Bold any text.
这篇关于在C#Windows应用程序中使用通用/文本打印机更改字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!