Windows Develop Bookmark and Share   
 index > Windows Forms General > Insert a Resourse to textbox?
 

Insert a Resourse to textbox?

Hey,

how do you insert a resourse(image in resourses) to a rich textbox?

I tryed doing this:

thisrichtextbox.TextBox.SelectedText = Notebook_Pro.Properties.Resources.theimage;

but I got an error about it not being able to convert bitmap to string...so I tryed the code I had gotten from a question I asked when I was progames25 about inserting a image form a file into the textbox...:

string strImagePath = openFileDialog1.FileName;

Image img = Image.FromFile(strImagePath);

Clipboard.SetDataObject(img);

DataFormats.Format df = DataFormats.GetFormat(DataFormats.Bitmap); //Check this line, im not sure

if (thisrichtextbox.TextBox.CanPaste(df))

{

thisrichtextbox.TextBox.Paste(df);

}

and changed allt he image from files and open dialog stuff to the programname.properties.resourses.imagename but I got that same error...

So now I dunno what to do...

thanks :)

programmer01  Saturday, October 07, 2006 5:56 PM

anyone?

Thanks :)

programmer01  Sunday, October 08, 2006 9:02 PM
Pasting into a textbox only works if the data in the clipboard is text. As far as I know the only way to do this is to manually insert the correctRTF tags into the Rtf property of the RichTextBox. I am not familar with RTF tags, so I can't help you with the details, but if you search around you can probably find examples.
CommonGenius.com  Tuesday, October 10, 2006 6:08 AM

ok, I will test it out

programmer01  Wednesday, October 11, 2006 12:55 AM
CommonGenius.com wrote:
... I am not familar with RTF tags...
I once used the RTF tags, and I have to say to it's a nightmare to use the tags manually. It would be better to use some wrappers for RTF tags.
gqlu  Wednesday, October 11, 2006 2:44 AM
I wonder the richtextbox has the rendering engine for the image. As we manually copy a jpg image and paste it into the richtextbox, it won't be shown, though there is a space there saying 'JPEG image'.
gqlu  Wednesday, October 11, 2006 2:48 AM

Do not use the 'TextBox' - work directly with the Richtextbox - It works

Dim img As Bitmap

img = CType(Image.FromFile("C:\Documents and Settings\laoai\My Documents\My Pictures\test.jpg"), Bitmap)

Clipboard.Clear()

Clipboard.SetDataObject(img, False)

RichTextBox2.Paste(DataFormats.GetFormat(DataFormats.Bitmap)) 'No RichTextBox2.TextBox.Paste ...

SRIRAM RAJAMANURI  Wednesday, October 11, 2006 2:35 PM

Well, the .Textbox is what holds all the stuff the normal richtextbox would have, but if I did not use the .Textbox nothing would happen, and somtimes I would get an error...

But the code you gave me looks like it is doing the same thing that already works for me...But what I am trying to do is get a image program the resourses of my project and add it to the richtextbox....

Thanks :)

programmer01  Wednesday, October 11, 2006 2:45 PM

You can use google to search for other answers

Custom Search

More Threads

• How to allow edit of Multi-line text in a DataGridView cell
• How i can remove W32.Blackmal.E@mm
• MaskedTextbox and allowing only valid int input
• MonthCalendar control - formatting problem
• ComboBox Font
• Sending messages or keystrokes to external process that is not in focus.
• C# VS 2008 User control drawn on a tab control does not show correct version
• How to place tabs at the bottom of a TabControl
• Problem in auto scroll of window form.
• Get media position from axMediaPlayer object while playing