Insert image into RichTextBox

I have a RichTextBox , and when I try to insert an image into it, I get an icon inserted instead of the image itself. How to get the image pasted into it?

+4
source share
1 answer

I did it once. You must place the Key Down event in the richtextbox. Try the following:

  private void RtbDocKeyDown(object sender, KeyEventArgs e) { if (e.Modifiers == Keys.Control && e.KeyCode == Keys.V) { DataFormats.Format df = DataFormats.GetFormat(DataFormats.Bitmap); StringCollection strcollect = Clipboard.GetFileDropList(); Image image= Image.FromFile(strcollect[0]); Clipboard.Clear(); Clipboard.SetImage(image); if (Clipboard.ContainsImage()) { rtbBody.Paste(df); e.Handled = true; Clipboard.Clear(); } } 

Hope this helps.

0
source

All Articles