从剪贴板或通过拖放将图像插入RadRichTextBox(Telerik)

时间:2016-11-24 08:32:10

标签: wpf telerik richtextbox

是否可以从剪贴板或通过拖放来将图像插入Telerik RadRichTextBox?

我尝试将复制的图像粘贴到剪贴板。正如我们在下面的照片中看到的那样,白色背景的东西被插入。但这不是一张预期的照片。

enter image description here



<telerik:RadRichTextBox x:Name="RADRichTextBox" MaxWidth="250" BorderBrush="Black" IsSelectionMiniToolBarEnabled="True" DocumentInheritsDefaultStyleSettings="True" FontSize="14" ForceCursor="True" IsSpellCheckingEnabled="True" Height="50" MaxHeight="100">
      <telerik:RadDocument x:Name="RADDocument" DefaultPageLayoutSettings="600,800" />
</telerik:RadRichTextBox>
&#13;
&#13;
&#13;

提前谢谢!

1 个答案:

答案 0 :(得分:0)

  1. 添加活动:
  2. CommandExecuting="RADRichTextBox_CommandExecuting"

    1. 将此代码粘贴到créated事件中:
    2. if (e.Command is PasteCommand)
          {
              e.Cancel = true;        
              if (System.Windows.Forms.Clipboard.ContainsImage())
                 {
                     MemoryStream lStream = new MemoryStream();
                     System.Drawing.Image lImage = null;
                      
                     lImage = System.Windows.Forms.Clipboard.GetImage();
                      
                     lImage.Save(lStream, System.Drawing.Imaging.ImageFormat.Png);
                     lStream.Position = 0;
                      
                     this.RADRichTextBox.InsertImage(lStream, "Png");
                  }
                      
               else if (System.Windows.Forms.Clipboard.ContainsText())
                  {               
                          this.RADRichTextBox.Insert(System.Windows.Forms.Clipboard.GetText());
                  }
           }