G
Guest
Hi
I am trying to print table format text out in C#. The approach I use is to format the string varaible a
temp=string.Format("{0,-10}{1,-8}{2,-12}",id,name,cost)
Then I keep adding values by useing temp=temp+"\n"+string.fromat...
At the end, I put the string variable to a memorystream and send it to printer
The problem is that it looks ok if I use Console.WriteLine to print out hte string in console windows, all aligned as I expected, but it does not align well after out to printer. I tried padright with '-' to see what is going on, it seems that each character has different width and it is handled nicely by WriteLine in console, but not working while sending to printer, so I could get something lik
ID Name Cos
1 Chris 1.
12 Jason 2.
I looked through the newsgroup but I can not find any solution for it
Could anyone here please help me out on this
Thanks a loooooooo
CHri
MemoryStream ms = new MemoryStream((new System.Text.ASCIIEncoding()).GetBytes(stringToPrint))
StreamReader streamToPrint = new StreamReader(ms)
try
//Assumes the default printe
TextFilePrintDocument pd = new TextFilePrintDocument(streamToPrint)
PrintDialog dlg = new PrintDialog()
dlg.Document = pd
DialogResult result = dlg.ShowDialog()
if (result == DialogResult.OK)
pd.Print()
I am trying to print table format text out in C#. The approach I use is to format the string varaible a
temp=string.Format("{0,-10}{1,-8}{2,-12}",id,name,cost)
Then I keep adding values by useing temp=temp+"\n"+string.fromat...
At the end, I put the string variable to a memorystream and send it to printer
The problem is that it looks ok if I use Console.WriteLine to print out hte string in console windows, all aligned as I expected, but it does not align well after out to printer. I tried padright with '-' to see what is going on, it seems that each character has different width and it is handled nicely by WriteLine in console, but not working while sending to printer, so I could get something lik
ID Name Cos
1 Chris 1.
12 Jason 2.
I looked through the newsgroup but I can not find any solution for it
Could anyone here please help me out on this
Thanks a loooooooo
CHri
MemoryStream ms = new MemoryStream((new System.Text.ASCIIEncoding()).GetBytes(stringToPrint))
StreamReader streamToPrint = new StreamReader(ms)
try
//Assumes the default printe
TextFilePrintDocument pd = new TextFilePrintDocument(streamToPrint)
PrintDialog dlg = new PrintDialog()
dlg.Document = pd
DialogResult result = dlg.ShowDialog()
if (result == DialogResult.OK)
pd.Print()