RichTextBox.CanPaste(DataFormats+Format) 메서드

정의

지정된 데이터 형식으로 클립보드의 정보를 붙여넣을 수 있는지 여부를 확인합니다.

public:
 bool CanPaste(System::Windows::Forms::DataFormats::Format ^ clipFormat);
public bool CanPaste (System.Windows.Forms.DataFormats.Format clipFormat);
member this.CanPaste : System.Windows.Forms.DataFormats.Format -> bool
Public Function CanPaste (clipFormat As DataFormats.Format) As Boolean

매개 변수

clipFormat
DataFormats.Format

DataFormats.Format 값 중 하나입니다.

반환

지정된 데이터 형식으로 클립보드의 데이터를 붙여넣을 수 있으면 true이고, 그렇지 않으면 false입니다.

예제

다음 코드 예제를 사용 Paste 하는 방법을 보여 줍니다는 비트맵을 붙여넣는 메서드를 컨트롤입니다 RichTextBox . 파일에서 비트맵을 연 후 예제에서는 메서드를 SetDataObject 사용하여 비트맵을 Windows 클립보드에 복사합니다. 마지막으로 이 예제에서는 개체의 형식을 Bitmap 검색하고 메서드를 사용하여 CanPaste 형식을 컨트롤에 붙여넣을 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

설명

사용자가 정보를 RichTextBox 컨트롤에 붙여넣을 수 있도록 설정하기 전에 이 메서드를 사용하여 클립보드의 현재 콘텐츠가 지정된 클립보드 데이터 형식인지 여부를 확인할 수 있습니다. 예를 들어 붙여넣기 명령 MenuItem 의 이벤트에 대한 Popup 이벤트 처리기를 만들고 이 메서드를 사용하여 클립보드의 데이터 형식에 따라 붙여 MenuItem 넣기를 사용할지 여부를 결정할 수 있습니다.

적용 대상

추가 정보