<RichTextBox x:Name="text_rich" > <FlowDocument > <Paragraph/> </FlowDocument> </RichTextBox> 

When copying a picture (file) from the disk does not work. It works only when copying a picture from a text document.

enter image description here

So it is inserted from the file and how from the buffer?

This is how the file is inserted from the file, and this image file is needed from the buffer.

 BitmapImage bitmap = new BitmapImage(new Uri(@"z:\DOWNLOADS\avatar145693_6.gif")); Clipboard.SetImage(bitmap); text_rich.Paste(); 
  • one
    And Ctrl-V is not suitable? - VladD
  • no .................. - codename0082016
  • Why? Explain (probably better right in the question). - VladD
  • Ctrl-V doesn't work - nothing happens. Insertion is not active in the context menu of richtextbox - codename0082016
  • Unclear. Need to insert via UI? It works for me with the usual Ctrl-V. Or do you need to insert it programmatically? Just do text_rich.Paste(); - VladD

2 answers 2

Doing something like this:

  private void createImage(Control item) { Hashtable image = new Hashtable(1); image.Add(item,yourproject.Properties.Resources.yourpicturename); Clipboard.SetImage((Image)image[item]); ((RichTextBox)item).Paste(); } 
  • Uh ... And why in the code Hashtable ? - VladD
  • @VladD code is not mine. Found in google. Yes it is over - iluxa1810
  • one
    Well, you publish under your own name? You are for it and in response. - VladD February

So the picture is inserted:

  //Если у нас в буфере не было рисунка, но возможно был скопирован //файл рисунка в буфер, то //Создаем список в который поместим все скопированные // имена файлов из буфера List<string> addFileName = new List<string>(); //помещаем foreach (var filename in Clipboard.GetFileDropList()) { // string ext = (Path.GetExtension(filename)).ToLower(); if (ext == ".bmp" || ext == ".gif" || ext == ".jpeg" || ext == ".jpg" || ext == ".tif" || ext == ".tiff" || ext == ".png" || ext == ".wmf" || ext == ".emf") { addFileName.Add(filename.ToString()); BitmapImage bitmap = new BitmapImage(new Uri(filename)); Clipboard.SetImage(bitmap); text_rich.Paste(); } } //Проверяем если имен файлов нет, то выводим об этом сообщение if (addFileName.Count < 1) { MessageBox.Show("not image"); return; } //Очищаем буфер //Clipboard.Clear(); 
  • If you insert programmatically, then you do not need a buffer in theory. - VladD