RichTextBox.Paste(DataFormats+Format) 메서드

정의

클립보드의 내용을 지정된 클립보드 형식으로 붙여넣습니다.

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 호출하여 적절한 데이터 형식으로 붙여넣기 작업을 수행할 수 있습니다.

적용 대상

추가 정보