RichTextBox.Paste(DataFormats+Format) Metoda

Definicja

Wkleja zawartość Schowka w określonym formacie Schowka.

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)

Parametry

clipFormat
DataFormats.Format

Format Schowka, w którym dane powinny zostać uzyskane ze Schowka.

Przykłady

W poniższym przykładzie kodu pokazano, jak za pomocą Paste metody wkleić mapę bitową do kontrolki RichTextBox . Po otwarciu mapy bitowej z pliku przykład używa SetDataObject metody , aby skopiować mapę bitową do schowka systemu Windows. Na koniec przykład pobiera format Bitmap obiektu, sprawdza, czy format można wkleić do RichTextBox kontrolki i używa Paste metody do wklejania danych.

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

Uwagi

Za pomocą tej metody można wkleić dane ze schowka do kontrolki. Ta wersja Paste metody różni się od TextBoxBase.Paste metody , ponieważ umożliwia wklejanie tylko tekstu w określonym formacie Schowka. Możesz użyć CanPaste metody , aby określić, czy dane w Schowku mają określony format Schowka. Następnie możesz wywołać tę wersję metody, Paste aby upewnić się, że operacja wklejania jest wykonywana przy użyciu odpowiedniego formatu danych.

Dotyczy

Zobacz też