Pasting a BMP file into RichTextBox

J

Just Me

I've seen code that copies a bmp file into a RichTextBox by first putting it
into the clipboard and then using Paste to get it into the RichtextBox. This
destroys the clipboard contents.

Is there an easy way to save the clipboard contents and then restore it?


Thanks
 
J

Just Me

Thanks but I'd rather not use that control.

As to my question, Isn't there an easy way to grab the clipboard contents
and later restore them?

Thanks
 
H

Herfried K. Wagner [MVP]

Just Me said:
As to my question, Isn't there an easy way to grab the clipboard contents
and later restore them?

Untested:

\\\
Dim ClipboardContent As Image = _
DirectCast( _
Clipboard.GetDataObject().GetData(DataFormats.Bitmap), _
Image _
)
Dim img As Image = Image.FromFile("C:\WINDOWS\Angler.bmp")
Clipboard.SetDataObject(img)
RichTextBox1.Paste()
If Not ClipboardContent Is Nothing Then
Clipboard.SetDataObject(ClipboardContent, True)
ClipboardContent.Dispose()
End If
img.Dispose()
///
 
J

Just Me

I'll test it

Herfried K. Wagner said:
Untested:

\\\
Dim ClipboardContent As Image = _
DirectCast( _
Clipboard.GetDataObject().GetData(DataFormats.Bitmap), _
Image _
)
Dim img As Image = Image.FromFile("C:\WINDOWS\Angler.bmp")
Clipboard.SetDataObject(img)
RichTextBox1.Paste()
If Not ClipboardContent Is Nothing Then
Clipboard.SetDataObject(ClipboardContent, True)
ClipboardContent.Dispose()
End If
img.Dispose()
///
 
S

Supra

me 2.. i will not used third party.

Just said:
Thanks but I'd rather not use that control.

As to my question, Isn't there an easy way to grab the clipboard contents
and later restore them?

Thanks
 
J

Just Me

me 2.. i will not used third party.

Thanks





Just Me wrote:

Thanks but I'd rather not use that control.

As to my question, Isn't there an easy way to grab the clipboard contents
and later restore them?

Thanks




I've seen code that copies a bmp file into a RichTextBox by first putting
it into the clipboard and then using Paste to get it into the
RichtextBox. This destroys the clipboard contents.

You may want to use this extended richtextbox control instead of the
standard richtextbox:

Insert Plain Text and Images into RichTextBox at Runtime
<URL:http://www.codeproject.com/cs/miscctrl/CsExRichTextBox.asp>
 

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