RichTextBox.Paste(DataFormats+Format) Méthode

Définition

Colle le contenu du Presse-papiers dans le format de Presse-papiers spécifié.

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)

Paramètres

clipFormat
DataFormats.Format

Format de Presse-papiers dans lequel les données doivent être obtenues du Presse-papiers.

Exemples

L’exemple de code suivant montre comment utiliser la Paste méthode pour coller une bitmap dans le RichTextBox contrôle. Après avoir ouvert une bitmap à partir d’un fichier, l’exemple utilise la SetDataObject méthode pour copier l’image bitmap dans le Presse-papiers Windows. Enfin, l’exemple récupère le format de l’objet Bitmap , vérifie que le format peut être collé dans le RichTextBox contrôle et utilise la Paste méthode pour coller les données.

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

Remarques

Vous pouvez utiliser cette méthode pour coller des données du Presse-papiers dans le contrôle. Cette version de la Paste méthode est différente de la TextBoxBase.Paste méthode, car elle vous permet de coller uniquement du texte au format Presse-papiers spécifié. Vous pouvez utiliser la CanPaste méthode pour déterminer si les données du Presse-papiers sont au format Presse-papiers spécifié. Vous pouvez ensuite appeler cette version de la Paste méthode pour vous assurer que l’opération de collage est effectuée avec le format de données approprié.

S’applique à

Voir aussi