Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Разработка Windows Forms > PrintPreview(не отображается text)


Автор: shark1 28.9.2008, 10:25
Почему то не отображается text.Пытаюсь вывести на печать текст,но почемуто его не видно.Плизззззз,подскажите где ошибка.
Зарание спасибо.
Код:
Код

static int intCurrentChar;
        private StringReader stringReader;
        private Font currentFont = null;

private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            Font font2 = new Font("Microsoft Sans Serif", 13);    

            textBox1.Font = new Font(textBox1.Font, FontStyle.Regular); ;
           
            this.textBox1.Text ="TO :   " + this.txt_ClientNameMail.Text;        



            int intPrintAreaHeight;
            int intPrintAreaWidth;
            int marginLeft;
            int marginTop;

            e.Graphics.DrawImage(this.pictureBox12.Image, 5, 5, this.pictureBox12.Size.Width, this.pictureBox12.Size.Height);
            e.Graphics.DrawImage(this.pictureBox11.Image, 135, 85, this.pictureBox11.Size.Width, this.pictureBox11.Size.Height);
            textBox1.Text = "";
            intPrintAreaHeight = printDocument1.DefaultPageSettings.PaperSize.Height - printDocument1.DefaultPageSettings.Margins.Top - printDocument1.DefaultPageSettings.Margins.Bottom;
            intPrintAreaWidth = printDocument1.DefaultPageSettings.PaperSize.Width - printDocument1.DefaultPageSettings.Margins.Left - printDocument1.DefaultPageSettings.Margins.Right;
            printDocument1.DefaultPageSettings.Margins.Bottom = 0; // 0,5 inches
            printDocument1.DefaultPageSettings.Margins.Top = 0; // 0,5 inches
            printDocument1.DefaultPageSettings.Margins.Left = 0; // 0,5 inches
            printDocument1.DefaultPageSettings.Margins.Right = 0; // 0,5 inches


            marginLeft = printDocument1.DefaultPageSettings.Margins.Left; // X coordinate
            marginTop = printDocument1.DefaultPageSettings.Margins.Top; // Y coordinate

                int intTemp = intPrintAreaHeight;
                intPrintAreaHeight = intPrintAreaWidth;
                intPrintAreaWidth = intTemp;
          

            int intLineCount = (int)(intPrintAreaHeight / font2.Height);

            // Initialize the rectangle structure that defines the printing area.

            RectangleF rectPrintingArea = new RectangleF(marginLeft, marginTop, intPrintAreaWidth, intPrintAreaHeight);


            StringFormat sfmt = new StringFormat(StringFormatFlags.LineLimit);

            int intLinesFilled;
            int intCharsFitted;

            e.Graphics.MeasureString(textBox1.Text.Substring(intCurrentChar), font2, new SizeF(intPrintAreaWidth, intPrintAreaHeight), sfmt, out intCharsFitted, out intLinesFilled);

            // Print the text to the page.

            e.Graphics.DrawString(textBox1.Text.Substring(intCurrentChar), font2, Brushes.Black, rectPrintingArea, sfmt);

        
            intCurrentChar += intCharsFitted;


            if (intCurrentChar < (textBox1.Text.Length - 1))
            {
                e.HasMorePages = true;
            }
            else
            {
                e.HasMorePages = false;
                
                intCurrentChar = 0;
            }
        }


        private void button1_Click(object sender, EventArgs e)
        {
            PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog();


            try
            {
                printDocument1.DefaultPageSettings.Landscape = true;
                printDocument1.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("No.10envelope", 104, 241);

                printPreviewDialog1.Document = printDocument1;
                printPreviewDialog1.ShowDialog();

            }
            catch
            {

                MessageBox.Show("An error occurred while trying to load the " +
                    "document for Print Preview. Make sure you currently have " +
                    "access to a printer. A printer must be connected and " +
                    "accessible for Print Preview to work.", this.Text,
                    MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
        }

Автор: shark1 28.9.2008, 11:39
Как то криво все получается.Текст появляется после второго нажатия на кнопку,и почему то в левом верхнем углу.Как мне его сдвинуть на центр конверта.Спасибо.

Добавлено через 4 минуты и 38 секунд
Как сдвинуть разобрался надо через:
printDocument1.DefaultPageSettings.Margins.Bottom = 0; 
            printDocument1.DefaultPageSettings.Margins.Top = 50; // 0,5 inches
            printDocument1.DefaultPageSettings.Margins.Left = 50; // 0,5 inches
            printDocument1.DefaultPageSettings.Margins.Right = 0; 
а вот почему отображается только по второму нажатию,в чем ошибка.Спасибо.

Автор: shark1 28.9.2008, 13:09
Vopros snimaetsa.Vsem spasibo.

Автор: shark1 29.9.2008, 01:12
HELP ME PLEASE.
Весь код неработает,попробовал распичатать,а оно мало того что паспечатало не вдоль а поперёк конверта,так еще и мелко мелко в самом верху.Короче неработает нечего.Помогите где я ошибаюсь.Зарание спасибо.

Автор: shark1 29.9.2008, 18:04
Ну все сдаюсь прошу помощи.Непонимаю в printpreview показывает вроде нормальный размер,а когда выдаю на печать то принтер вообще пичатает в другой стороне от конверта.Плизззззззззззззз помогите с этим делом ,очень надо ,а я застрял :( :(:(
Зарание спасибо.

Автор: shark1 30.9.2008, 07:37
Ну где же помощь.Плизззззззззззззз :(

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)