.net 2005 的winfrom 中怎么打印中文啊?????????
我写的打印出来后,英文可以正常打印,可是中文显示乱码!! 请教高手,用设置字符集之类的么?下边是代码:
private Font printFont;
private StreamReader streamToPrint;//声明打印流
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
float linesPerPage = 0; //每页的行数
float yPos = 0;
int count = 0;
float leftMargin = e.MarginBounds.Left;
float topMargin = e.MarginBounds.Top;
string line = null;
// 计算每页的行数.
linesPerPage = e.MarginBounds.Height /printFont.GetHeight(e.Graphics);
// 打印每页的行内容.
while (count < linesPerPage &&
((line = streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count *printFont.GetHeight(e.Graphics));
e.Graphics.DrawString(line, printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
count++;
}
// 如果还有更多页,继续打印.
if (line != null)
e.HasMorePages = true;
else
e.HasMorePages = false;
}
//打印按钮Click 事件
private void button1_Click(object sender, EventArgs e)
{
string filePath = this.textBox1.Text;
if (filePath != "")
{
try
{
//指定打印文件
streamToPrint = new StreamReader(filePath);
try
{
printFont = new Font("宋体", 10); //指定字体
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(this.printDocument1_PrintPage);
pd.Print();
}
finally
{
streamToPrint.Close();//释放资源
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
{
MessageBox.Show("请选择要打印的文件","");
}
}
补充:.NET技术 , C#