Click here to Skip to main content
15,920,503 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want text printing in C# Windows Application.
For this I installed a Generic/Text Printer.
in C Sharp Code I have written as :
C#
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);
            }


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
Posted
Updated 21-Dec-11 3:58am
v2

1 solution

C#
dwon = string.Format("{0}{1}", Convert.ToChar(27), Convert.ToChar(69));
dwof = string.Format("{0}{1}", Convert.ToChar(27), Convert.ToChar(70));



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.
 
Share this answer
 
Comments
Manoj Dua 21-Dec-11 22:32pm    
I not understand you answer.
Please tell me right code
ThomasCarmen 22-Dec-11 20:26pm    
It is a greagt answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900