By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,124 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

inserting images in richtextbox

P: n/a
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.

Dec 8 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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?

--
Dave Sexton

<fa*************@gmail.comwrote in message
news:11*********************@80g2000cwy.googlegrou ps.com...
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.

Dec 8 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.