我想从文本框中显示我的僧伽罗语文本的打印预览。在这里我使用了打印预览对话框
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();
}
这可行,但我的文字是“අම්මා”,但它以这种方式显示අ්මමා“所以请帮助我以正确的方式显示。
我想打印 TextBox 的内容,所以我试图从 TextBox 中制作一个 PrintDocument。但我找不到将简单的 TextBox 转换为 PrintDocument 的方法。有任何想法吗?