RichTextBox.Paste(DataFormats+Format) 方法   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
粘贴指定剪贴板格式的剪贴板内容。
public:
 void Paste(System::Windows::Forms::DataFormats::Format ^ clipFormat);
	public void Paste (System.Windows.Forms.DataFormats.Format clipFormat);
	override this.Paste : System.Windows.Forms.DataFormats.Format -> unit
	Public Sub Paste (clipFormat As DataFormats.Format)
	参数
- clipFormat
 - DataFormats.Format
 
数据应从剪贴板获得的剪贴板格式。
示例
下面的代码示例演示如何使用 Paste 该方法将位图粘贴到控件中 RichTextBox 。 从文件打开位图后,该示例使用SetDataObject该方法将位图复制到Windows剪贴板。 最后,该示例检索对象的格式 Bitmap ,验证格式是否可以粘贴到 RichTextBox 控件中,并使用 Paste 该方法粘贴数据。
private:
   bool pasteMyBitmap( String^ fileName )
   {
      // Open an bitmap from file and copy it to the clipboard.
      Bitmap^ myBitmap = gcnew Bitmap( fileName );
      // Copy the bitmap to the clipboard.
      Clipboard::SetDataObject( myBitmap );
      // Get the format for the object type.
      DataFormats::Format^ myFormat = DataFormats::GetFormat( DataFormats::Bitmap );
      // After verifying that the data can be pasted, paste it.
      if ( richTextBox1->CanPaste( myFormat ) )
      {
         richTextBox1->Paste( myFormat );
         return true;
      }
      else
      {
         MessageBox::Show( "The data format that you attempted to paste is not supported by this control." );
         return false;
      }
   }
private bool pasteMyBitmap(string fileName)
{
    // Open an bitmap from file and copy it to the clipboard.
    Bitmap myBitmap = new Bitmap(fileName);
            
    // Copy the bitmap to the clipboard.
    Clipboard.SetDataObject(myBitmap);
    // Get the format for the object type.
    DataFormats.Format myFormat = DataFormats.GetFormat(DataFormats.Bitmap);
    // After verifying that the data can be pasted, paste it.
    if(richTextBox1.CanPaste(myFormat))
    {
        richTextBox1.Paste(myFormat);
        return true;
    }
    else
    {
        MessageBox.Show("The data format that you attempted to paste is not supported by this control.");
        return false;
    }
}
Private Function PasteMyBitmap(ByVal Filename As String) As Boolean
    'Open an bitmap from file and copy it to the clipboard.
    Dim MyBitmap As Bitmap
    MyBitmap = Bitmap.FromFile(Filename)
    ' Copy the bitmap to the clipboard.
    Clipboard.SetDataObject(MyBitmap)
    ' Get the format for the object type.
    Dim MyFormat As DataFormats.Format = DataFormats.GetFormat(DataFormats.Bitmap)
    ' After verifying that the data can be pasted, paste it.
    If RichTextBox1.CanPaste(MyFormat) Then
        RichTextBox1.Paste(MyFormat)
        PasteMyBitmap = True
    Else
        MessageBox.Show("The data format that you attempted to paste is not supported by this control.")
        PasteMyBitmap = False
    End If
End Function
	注解
可以使用此方法将数据从剪贴板粘贴到控件中。 此方法的 Paste 此版本不同于该方法, TextBoxBase.Paste 因为它允许仅粘贴指定剪贴板格式的文本。 可以使用 CanPaste 该方法来确定剪贴板中的数据是否采用指定的剪贴板格式。 然后,可以调用此方法的 Paste 此版本,以确保使用适当的数据格式执行粘贴操作。