2016-11-24 41 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()); 
     
          } 
     
        }

    相關問題