From: Mansi Shah on
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.

*** Sent via Developersdex http://www.developersdex.com ***
From: AMercer on
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" wrote:

> 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.
>
> *** Sent via Developersdex http://www.developersdex.com ***
>
From: Lloyd Sheen on

"Mansi Shah" <mansi(a)devdex.com> wrote in message
news:O6U85bYcJHA.5788(a)TK2MSFTNGP03.phx.gbl...
> 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.
>
> *** Sent via Developersdex http://www.developersdex.com ***

Every control has a DrawToBitmap function which returns a bitmap.

LS

From: Herfried K. Wagner [MVP] on
"AMercer" <AMercer(a)discussions.microsoft.com> schrieb:
> 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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>