How to insert an Image into a RichTextBox?

Kenta

Member
Joined
Mar 17, 2012
Messages
21
Programming Experience
Beginner
I want to know how to insert an image/images into a RichTextBox, that the user specifies while the application is running...

Thank you !
 
You can use Clipboard.SetImage and RichTextBox.Paste methods to do this. Image.FromFile method if user specifies a image file.
 
You can use Clipboard.SetImage and RichTextBox.Paste methods to do this. Image.FromFile method if user specifies a image file.

Well, I have used the following code:
Dim Open As New OpenFileDialog
Open.Filter = "png|*.png"
Open.ShowDialog()

Dim strFileName As Image = Image.FromFile(Open.FileName)
Clipboard.SetImage(strFileName)
Me.document.Paste()


where document is the name of my RichTextBox .... the problem now is that when I close my editor the image that i inserted disappears >< ... How can I fix this?
 
when I close my editor the image that i inserted disappears
What does this mean? Are you asking how to save rtf file?
 
Inserting an image into a Rich Text Box

Hello All!
Well I'm having a probelm with the insertion of an image into the RichTextBox ... I can insert it into the RTB but when I save the file and try to open it once again the image won't appear... how can I fix this?

code>>
------------

Dim Open As New OpenFileDialog
Open.Filter = "png|*.png"
Open.ShowDialog()

Dim strFileName As Image = Image.FromFile(Open.FileName)
Clipboard.SetImage(strFileName)
Me.document.Paste()



---------
Knowing that document is the name of my Rich Text Box...
 
Did you follow my previous advice to use SaveFile method? Did you use LoadFile method to load file? I have of course tested this and know it works...
 
Did you follow my previous advice to use SaveFile method? Did you use LoadFile method to load file? I have of course tested this and know it works...


Well I have, because i'm implementing a function for the saving, & it contains what you've explained, just as follows:
Dim Save As New SaveFileDialog
Dim myStreamWriter As System.IO.StreamWriter
Save.Filter = "RichTextFormat (RTF Files)|*.rtf|Text (*.txt)|*.txt|HTML (*.html*)| *.html| PHP (*.php)|*.php*|All Files (*.*)|*.*"

Save.CheckPathExists = True
Save.Title = "Save File"
Save.ShowDialog(Me)

Try
myStreamWriter = System.IO.File.AppendText(Save.FileName)
myStreamWriter.Write(document.Text)
myStreamWriter.Flush()

Catch ex As Exception


But the main problem is for saving the image, for instance if i have included a text with the image and save the file, when i re-open it the text is there but not the image!
 
No, you haven't.

I'm sorry for the inconvenience ... but this is how I used the three things you mentioned > user specifies the image, clipboard saving and pasting it to the Rich Text Box :
Dim strFileName As Image = Image.FromFile(Open.FileName)
Clipboard.SetImage(strFileName)
Me.document.Paste()

The previous reply is for the saving ... could you explain your idea more please?
 
I'm telling you to use the SaveFile/LoadFile methods, what is there to explain? There is even code samples in documentation, and I even posted documentation link online for you.
 
I'm telling you to use the SaveFile/LoadFile methods, what is there to explain? There is even code samples in documentation, and I even posted documentation link online for you.
Yes you have, thank you so much... i wasn't paying attention and i'm new at vb.net... :encouragement:
 
Back
Top