我希望从文本框中显示我的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();
}
这样可行,但我的文字是&#34;අම්මා&#34;但它以这种方式显示අ්මමා&#34;所以请以正确的方式帮助我。
我想打印TextBox的内容,所以我正在尝试从TextBox中创建一个PrintDocument。但我找不到将简单的TextBox转换为PrintDocument的方法。有什么想法吗?
答案 0 :(得分:0)
基于这一大堆代码,我最好的猜测是在streamreaders(以及可能使用编码的其他对象)上指定编码。
但是,严肃地说,您应该清理代码并制作一个更小,更易于理解的示例来重现/演示您的问题。此外,名为linkLabel6
,printDialog1
,printDocument2
,linkLabel7
或textBox1
的变量也无济于事。