-1

我想从文本框中显示我的僧伽罗语文本的打印预览。在这里我使用了打印预览对话框

    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 的方法。有任何想法吗?

4

1 回答 1

0

基于这一大堆代码,我最好的猜测是在流读取器(可能还有其他使用编码的对象)上指定编码

但是,严肃地说,你应该清理你的代码并制作一个更小、更易于理解的示例来重现/演示你的问题。此外,命名为linkLabel6printDialog1、或的变量也无济于事。printDocument2linkLabel7textBox1

于 2012-07-17T23:33:34.527 回答