inserting images in richtextbox

  • Thread starter farrukhqadri786
  • Start date
F

farrukhqadri786

Hi!
I have an imageList and a richtextbox in a C# form. I want to insert
image from imageList into a richtextbox.

I have found the following code on net but it does'nt work.

InsertImage(EmotionsImageList.Images[0]);

public void InsertImage(Image pic)
{
//string lstrFile = fileDialog.FileName;
Bitmap myBitmap = new Bitmap(pic);
// Copy the bitmap to the clipboard.
Clipboard.SetDataObject(myBitmap);
// Get the format for the object type.
DataFormats.Format myFormat = DataFormats.GetFormat
(DataFormats.Bitmap);
// After verifying that the data can be pasted, paste
rtxtAllMessages.ReadOnly = false;
if(rtxtAllMessages.CanPaste(myFormat))
{
rtxtAllMessages.Paste(myFormat);
}
else
{
MessageBox.Show("The data format that you attempted site" +
" is not supported by this control.");
}
rtxtAllMessages.ReadOnly = true;
}


Can any one help me.
 
D

Dave Sexton

Hi,

I'm fairly certain there is a way by setting the Rtf property itself but I
don't remember how exactly - something like \pict is the RTF you'd need.

Anyway, if you aren't tied down to using RTF (if you're writing your own
chat client, for example) then you might want to try hosting a WebBrowser
control (2.0 framework) in design-mode instead. If you know HTML then
you'll have a much easier time using the WebBrowser control, and it's much
more flexible (e.g., javascript, edit designers).

"WebBrowser Control (Windows Forms)"
http://msdn2.microsoft.com/en-us/library/2te2y1x6.aspx

"DHTML document.designMode property"
http://msdn2.microsoft.com/en-us/library/ms533720.aspx

In case you really do need RTF here's a short article with some links to RTF
specifications:

"Rich Text Format"
http://en.wikipedia.org/wiki/Rich_Text_Format

If you'd prefer to just fix the code that you've posted then you're going to
have to supply more information, such as the error message, at least, and
either the stack trace or the line at which the exception is being thrown.

If you're not getting an error, then what unexpected behavior have you
observed from that code?
 

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