-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

この大量のコードに基づく私の最善の推測は、ストリームリーダー (およびエンコーディングを使用する他のオブジェクト) でエンコーディングを指定することです

しかし、真剣に、問題を再現/実証するために、コードをクリーンアップし、より小さく、より理解しやすい例を作成する必要がありました。また、linkLabel6printDialog1printDocument2linkLabel7またはのような名前の変数textBox1も役に立ちません。

于 2012-07-17T23:33:34.527 に答える