Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

could anybody solve this problem

here is my code
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace notepad_demo
{
    public partial class Form2 : Form
    {
        bool page = true;
       // private StringReader myReader;
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            this.pictureBox1.Location = new Point(16, 13);
            this.pictureBox1.Width = 850;
            this.pictureBox1.Height = 5750;
            //this.panel1.Location = new Point(128, 28);
            this.panel1.Width = 850;
            this.panel1.Height = 600;
            //this.panel1.AutoScroll = true;

            
        }

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            using (Font myFont = new Font("Arial", 14))
            {
                e.Graphics.DrawString("Hello 1", myFont, Brushes.Green, new Point(2, 2));
                e.Graphics.DrawString("Hello 2", myFont, Brushes.Green, new Point(2, 20));
                e.Graphics.DrawString("Hello 3", myFont, Brushes.Green, new Point(2, 120));
                e.Graphics.DrawString("Hello 4", myFont, Brushes.Green, new Point(2, 200));
                e.Graphics.DrawString("Hello 5", myFont, Brushes.Green, new Point(2, 302));
                e.Graphics.DrawString(textBox1.Text, myFont, Brushes.Green, new Point(2, 502));
                
            }
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            printDialog1.Document = printDocument1;
            
            if (printDialog1.ShowDialog() == DialogResult.OK)
            {

                printDocument1.Print();
            }
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            if (page)
            {
                float x = 20;
                float y = 100;
                Bitmap bmp = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);
                this.pictureBox1.DrawToBitmap(bmp, new Rectangle(0, 0, this.pictureBox1.Width, this.pictureBox1.Height));
                e.Graphics.DrawImage((Image)bmp, x, y);
                e.HasMorePages = true;
                page = false;
            }
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            printPreviewDialog1.Document = printDocument1;
            printPreviewDialog1.ShowDialog();
        }
    }
}

if i enterd more multi line text picturebox shown content ok,but not print full as per shown in picturebox.
its only print one page fit content balance text not print.
Posted
Updated 17-Oct-14 22:22pm
v2

1 solution

Well...why not code it to print more than one page?
Your current code:
C#
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
 {
     if (page)
     {
         ...
         e.HasMorePages = true;
         page = false;
     }

 }
will casue teh system to try and print a second page, but when the event is fired for it, you don't print anything because page is now false.

I think you need to work out exactly what you are trying to print where, and try coding the PrintPage handler again...
 
Share this answer
 
Comments
cadsolution 18-Oct-14 4:56am    
this is my textbox details
this.textBox1.Location = new System.Drawing.Point(11, 121);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBox1.Size = new System.Drawing.Size(100, 128);
this.textBox1.TabIndex = 4;
this.textBox1.Text = "1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23" +
"\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n32\r\n33\r\n34\r\n35\r\n36\r\n37\r\n38\r\n39\r\n40";

but my print or printpreview shown only 21 in one page
and balance not printed in second page

plz correct the code
OriginalGriff 18-Oct-14 5:19am    
No! :laugh:
I'm not doing your homework for you! ;)
It's up to you how much info you fit on which page: but you have to process the text (in the font and font size you want to print) and decide which text goes on which page - not me. Then you print the appropriate page of data until you print the last at which point you set HasMorePages to false.
cadsolution 21-Oct-14 1:22am    
hello,could anybody help for code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900