2012-07-17 105 views
-1

我想從文本框中顯示我的僧伽羅文本的打印預覽。在這裏我用的打印預覽對話框如何從文本框打印預覽我的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

回答

0

我最好的猜測,基於這個大混亂代碼,將指定編碼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