RichTextBox.Paste(DataFormats+Format) Método

Definición

Pega el contenido del Portapapeles en el formato de Portapapeles especificado.

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)

Parámetros

clipFormat
DataFormats.Format

Formato de Portapapeles en el que se obtendrán los datos del Portapapeles.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar el Paste método para pegar un mapa de bits en el RichTextBox control . Después de abrir un mapa de bits desde el archivo, en el ejemplo se usa el SetDataObject método para copiar el mapa de bits en el Portapapeles de Windows. Por último, el ejemplo recupera el formato del Bitmap objeto , comprueba que el formato se puede pegar en el RichTextBox control y usa el Paste método para pegar los datos.

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

Comentarios

Puede usar este método para pegar datos del Portapapeles en el control . Esta versión del Paste método es diferente del TextBoxBase.Paste método, ya que permite pegar solo texto en un formato de Portapapeles especificado. Puede usar el CanPaste método para determinar si los datos del Portapapeles están en el formato del Portapapeles especificado. A continuación, puede llamar a esta versión del Paste método para asegurarse de que la operación de pegado se realiza con el formato de datos adecuado.

Se aplica a

Consulte también