Could you please tell me how to insert an image using code. (I want to insert a logo at the top of each RichTextBox)
Can you tell me a way to save and retrieve images in RichTexBox. I fully understand it will something far from simple but any help would be appreciated. There does not seem to be anything in the documentation explaining how this might be done. I apologise if the subject is fully covered together with examples and I have just not seen it. If this is the case would you be kind enough to point out where it is.
Could I also ask how to move the cursor to the end of the document in code. (Using the keyboard, it is Ctrl+End)
Is it possilble to insert controls like textboxes etc. using code?
5 Answers, 1 is accepted
Thank you for the question.
To insert image using code you could do the following:
There is also another way to create ImageInline - from stream. This could be achieved with the following code:
If I have understand your question, you are asking for saving your document along with the inserted images and then loading it back. This could be done using the document format providers. For example you can save the document in .docx format in the following way:
To import it back again, you can use the following code:
To move to the document's end, you could do the following:
For more information you can look in our documentation.
I hope this helps and if you have any further questions - please feel free to ask.
the Telerik team
Many thanks for your reply.
Your suggestion on how to move to the end of document worked fine, thankyou.
I tried hard but I could not insert an image using the following code:
When I click on http://localhost:10220/ImageFolder/Desert.jpg the image opens in a separate window so I am guessing the address is correct.
However all that gets inserted into the RichTextBox is a blank space (200x15)
Regarding your suggeston on how to save and retrieve a document containg images to a database, could I ask for a little more help.
(However hard I try, I cannot think of any practical use for saving to disk so I am assuming your suggestion IS for saving to a database)
I can save and retrieve Xaml to a database using the following code but obviously images are not saved.
I tried changing XamlFormatProvider for DocxFormatProvider but I obviously did something wrong so I wonder if you might be kind enough to
expalin how to change the code.
Many thanks in anticipation.
Thanks a bunch for your question!
Actually there were 2 bugs (one of them unknown) which are now fix.
However you will be able to have the latest source code on Friday with latest internal build.
I found a temporary workaround for you which I hope will do the work. Please find a sample project attached.
The known bug was with import/export to XAML and it is with the images.
This bug is fixed by FixImages(..) method, which I have provided in the demo.
Let me know if this helps.
All the best,
the Telerik team
Thankyou for your sample project showing how to insert images.
Small projects like these are extremely useful as an aid to understanding.
I must admit though that I am not really clear about whether or not you have explained how to save and retrieve documents containing images to a database. Are you saying that this will possible on Friday? If so, when the bugs are fixed, I would be very grateful if you could then explain exactly how this might be done. Another small project would be very well received my myself and I suspect by others :-)
Overall, when everything is working smoothly, and adequate documentation is available, I believe the RadRichTextBox will be an excellent addition to the suite.
Thanks for your feedback - it is greatly appreciated!
To the question - when you export a document to XAML, the images are serialized in the XAML too. Our XAML format is a single file, which contains all document information needed (similar to DOCX or XPS files). And the fix for image problems will be available on Friday. You already have methods for saving/loading XAML document that use string. This means that you can store this strings to DB and later - load them back.
We have posted a sample on the forums using a DB:
Let me know if this helps or if you have any further questions.
the Telerik team