Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > How to print run time created controls.
 

How to print run time created controls.


hi,

I am creating rich text boxes at run time,here i want give all rich text boxes at single print job.

here all rich text boxes means,more then one rich text boxes are created at run time.
Venkat ------------------------------------------------ -------------------------------------------------------------------------------- Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Sincerely, Venkat
Venkat Chilkuri  Monday, August 31, 2009 1:43 PM

hi,

I am creating rich text boxes at run time,here i want give all rich text boxes at single print job.

here all rich text boxes means,more then one rich text boxes are created at run time.
Venkat ------------------------------------------------ -------------------------------------------------------------------------------- Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Sincerely, Venkat
Venkat Chilkuri  Monday, August 31, 2009 1:44 PM

Hi Venkat,

From your descript, you have put several rich text boxes on a form and want to print them together.

Based on my understanding, we can get the images of these rich text boxes and draw these images on one print page in the PrintPage event handler of the PrintDocument.

The code snippet below shows how to get an image of a RichTextBox:

[DllImport("gdi32.dll")]
static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int
nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);

//A method to draw a RichTextBox to an image.
private void DrawToBitmap(RichTextBox richTextBox, Bitmap image, Rectangle targetRectangle)
{

    Graphics g = richTextBox1.CreateGraphics();
    Graphics g2 = Graphics.FromImage(image);
    IntPtr gi = g.GetHdc();
    IntPtr gi2 = g2.GetHdc();
    BitBlt(gi2, 0, 0, richTextBox.Width, richTextBox.Height, gi, 0, 0, 0x00CC0020);
    g.ReleaseHdc();
    g2.ReleaseHdc();
    g.Dispose();
    g2.Dispose();
}

The code snippet below shows how to draw the images of several RichTextBoxes:

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
    //Geht the image of the first rich textbox.
    Bitmap img1 = new Bitmap(this.richTextBox1.Width,this.richTextBox1.Height);
    //Get the location, we need to adjust it based on the page bounds.
    Point loc1 = this.richTextBox1.Location;
    //Draw the rich textbox.
    e.Graphics.DrawImage(img1, loc1);

    //Get images of other rich textboxes and draw them.
}

Let me know if this does not help.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Wednesday, September 02, 2009 11:30 AM
Hi Venkat,

Could you please let me know if my reply helps or not?

Regards,
Aland Li

Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Friday, September 04, 2009 3:47 AM
Thanks,

But no use

Venkat ------------------------------------------------ -------------------------------------------------------------------------------- Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Sincerely, Venkat
Venkat Chilkuri  Friday, September 04, 2009 7:09 AM

You can use google to search for other answers

Custom Search

More Threads

• Where can i get the issuevision's c# code??
• problem with the update of the IssueVision
• dataservice.asmx
• Local Terrarium as Screensaver
• Timer Question
• How to install to a 3rd party remote server?
• Real time updates?
• Vacation form in outlook 2003, calculate time slot
• bowwow10 - how does he do it?
• When will the next version of terrarium be released?