다음을 통해 공유


RichTextBox.CanPaste 메서드

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

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
Public Function CanPaste ( _
    clipFormat As Format _
) As Boolean
‘사용 방법
Dim instance As RichTextBox
Dim clipFormat As Format
Dim returnValue As Boolean

returnValue = instance.CanPaste(clipFormat)
public bool CanPaste (
    Format clipFormat
)
public:
bool CanPaste (
    Format^ clipFormat
)
public boolean CanPaste (
    Format clipFormat
)
public function CanPaste (
    clipFormat : Format
) : boolean

매개 변수

반환 값

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

설명

이 메서드를 사용하면 RichTextBox 컨트롤에 정보를 붙여넣을 수 있도록 허용하기 전에 클립보드의 현재 내용이 지정된 클립보드 데이터 형식인지 여부를 확인할 수 있습니다. 예를 들어, 붙여넣기 명령 MenuItemPopup 이벤트에 대해 이벤트 처리기를 만들고 이 메서드를 사용하여 붙여넣기 MenuItem이 클립보드의 데이터 형식에 따라 활성화되는지 여부를 확인할 수 있습니다.

예제

다음 코드 예제에서는 Paste 메서드를 사용하여 RichTextBox 컨트롤에 비트맵을 붙여넣는 방법을 보여 줍니다. 이 예제에서는 파일에서 비트맵을 연 다음 SetDataObject 메서드를 사용하여 비트맵을 Windows 클립보드에 복사합니다. 마지막으로 Bitmap 개체 형식을 검색하고 CanPaste 메서드를 사용하여 해당 형식을 RichTextBox 컨트롤에 붙여넣을 수 있는지 확인한 다음 Paste 메서드를 사용하여 데이터를 붙여넣습니다.

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
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:
   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;
      }
   }

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

RichTextBox 클래스
RichTextBox 멤버
System.Windows.Forms 네임스페이스
Paste
DataFormats.Format 클래스