如何从文本框打印预览我的sinhala文本?

问题描述:

我想从文本框中显示我的僧伽罗文本的打印预览。在这里我用的打印预览对话框如何从文本框打印预览我的sinhala文本?

private void printDocument2_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs ev) 
    { 
     string strText = this.textBox1.Text; // read string from editor window 
     StreamReader myReader = new StreamReader(strText, System.Text.Encoding.ASCII, false); 
     int charactersOnPage = 5; 
     float linesPerPage = 0; 
     float yPosition = 0; 
     int count = 0; 
     float leftMargin = ev.MarginBounds.Left; 
     float topMargin = ev.MarginBounds.Top; 
     string line = null; 
     Font printFont = this.textBox1.Font; 
     SolidBrush myBrush = new SolidBrush(Color.Black); 
     // Work out the number of lines per page, using the MarginBounds. 
     linesPerPage = ev.MarginBounds.Height/printFont.GetHeight(ev.Graphics); 
     // Iterate over the string using the StringReader, printing each line. 
     while (count < linesPerPage && ((line = myReader.ReadLine()) != null)) 
     { 
      // calculate the next line position based on the height of the font according to the printing device 
      yPosition = topMargin + (count * printFont.GetHeight(ev.Graphics)); 
      // draw the next line in the rich edit control 
      ev.Graphics.DrawString(line, printFont, myBrush, leftMargin, yPosition, new StringFormat()); 
      count++; 
     } 
     // If there are more lines, print another page. 
     if (line != null) 
      ev.HasMorePages = true; 
     else 
      ev.HasMorePages = false; 
     myBrush.Dispose(); 
    } 

这工作,但我的文字是“අම්මා”,但它显示为这样අ්මමා”,请帮助我,它显示为正确的方法。

我要打印一个文本框的内容,所以我试图使一个PrintDocument的TextBox。但我没有找到一种方法来将一个简单的文本框转换为PrintDocument。任何想法?

+0

如果您花费最少的时间来检查您的代码是否已格式化,那么您更有可能获得帮助。认真地说,把**一些**的努力。 – Blorgbeard 2012-07-19 21:44:03

我最好的猜测,基于这个大混乱代码,将指定编码streamreaders(也可能是其他使用编码的对象)。

但是,严肃地说,你应该清理你的代码,并制作一个更小,更容易理解的例子来重现/展示你的问题。此外,名称为linkLabel6,printDialog1,printDocument2,linkLabel7textBox1的变量也没有帮助。

+0

thanx我用这个新的streamreaders现在打印预览不可见。 – user1531718 2012-07-17 23:52:40

+0

...那么?启动调试器!看看发生了什么。我们并不清楚!它也没有帮助,你*完全*删除你的代码... – RobIII 2012-07-17 23:53:19

+0

我添加了代码plzzzzzzzzzzz帮助 – user1531718 2012-07-18 00:19:32