Richtextbox to Image

  • Thread starter Thread starter Mansi Shah
  • Start date Start date
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.
 
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.
 
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
 
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.
 
Back
Top