我想從文本框中顯示我的僧伽羅文本的打印預覽。在這裏我用的打印預覽對話框如何從文本框打印預覽我的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。任何想法?
如果您花費最少的時間來檢查您的代碼是否已格式化,那麼您更有可能獲得幫助。認真地說,把**一些**的努力。 – Blorgbeard 2012-07-19 21:44:03