RichTextBox.CanPaste(DataFormats+Format) Metod

Definition

Avgör om du kan klistra in information från Urklipp i det angivna dataformatet.

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

Parametrar

clipFormat
DataFormats.Format

Ett av DataFormats.Format värdena.

Returer

trueom du kan klistra in data från Urklipp i det angivna dataformatet. annars . false

Exempel

I följande kodexempel visas hur du använder Paste metoden för att klistra in en bitmapp i RichTextBox kontrollen. När du har öppnat en bitmapp från filen använder exemplet metoden SetDataObject för att kopiera bitmappen till Windows Urklipp. Slutligen hämtar exemplet formatet för Bitmap objektet, använder CanPaste metoden för att kontrollera att formatet kan klistras in i RichTextBox kontrollen och använder Paste sedan metoden för att klistra in data.

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

Kommentarer

Du kan använda den här metoden för att avgöra om det aktuella innehållet i Urklipp är i ett angivet Urklippsdataformat innan användaren kan klistra in informationen i RichTextBox kontrollen. Du kan till exempel skapa en händelsehanterare för en Popup händelse av ett inklistringskommando MenuItem och använda den här metoden för att avgöra om inklistring MenuItem ska aktiveras baserat på typen av data i Urklipp.

Gäller för

Se även