2016-11-24 43 views
0

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

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

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>

预先感谢您!

回答

0
  1. 添加事件:

CommandExecuting="RADRichTextBox_CommandExecuting"

  • 粘贴该代码创建的事件内:
  • 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()); 
     
          } 
     
        }

    相关问题