Richtextbox to Image

M

Mansi Shah

Hi,

I have one pictruebox on which there is richtexbox.
When i print the picturebox it is not showing richtextbox in print.
It seems that printing richtextbox needs some more code to be added.
Is there any way by which i can convert richtextbox to image or bitmap,
so that i can print that?


Regards,
Mansi Shah.
 
A

AMercer

You can capture r as rectangle into bm as bitmap like this:

bm = New Bitmap(r.Width, r.Height, Imaging.PixelFormat.Format32bppArgb)
Using g As Drawing.Graphics = Drawing.Graphics.FromImage(bm)
g.CopyFromScreen(r.X, r.Y, 0, 0, r.Size, CopyPixelOperation.SourceCopy)
End Using

You may have to twiddle the PixelFormat parameter.
 
L

Lloyd Sheen

Mansi Shah said:
Hi,

I have one pictruebox on which there is richtexbox.
When i print the picturebox it is not showing richtextbox in print.
It seems that printing richtextbox needs some more code to be added.
Is there any way by which i can convert richtextbox to image or bitmap,
so that i can print that?


Regards,
Mansi Shah.

Every control has a DrawToBitmap function which returns a bitmap.

LS
 
H

Herfried K. Wagner [MVP]

AMercer said:
You can capture r as rectangle into bm as bitmap like this:

bm = New Bitmap(r.Width, r.Height, Imaging.PixelFormat.Format32bppArgb)
Using g As Drawing.Graphics = Drawing.Graphics.FromImage(bm)
g.CopyFromScreen(r.X, r.Y, 0, 0, r.Size,
CopyPixelOperation.SourceCopy)
End Using

You may have to twiddle the PixelFormat parameter.

However, note that this approach will only work if the relevant portion of
the richtextbox is visible.

For more complex scenarios, using 'EM_FORMATRANGE' might be an option:

HOW TO: Print the Content of a RichTextBox by Using Microsoft Visual Basic
..NET
<URL:http://support.microsoft.com/?scid=kb;EN-US;811401>

The target DC could be those wrapped by a 'Graphics' object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top