Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Bestimmt, ob Sie Informationen aus der Zwischenablage im angegebenen Datenformat einfügen können.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Syntax
'Declaration
Public Function CanPaste ( _
clipFormat As Format _
) As Boolean
'Usage
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
Parameter
- clipFormat
Einer der System.Windows.Forms.DataFormats.Format-Werte.
Rückgabewert
true, wenn Sie Daten aus der Zwischenablage im angegebenen Datenformat einfügen können, andernfalls false.
Hinweise
Mit dieser Methode können Sie feststellen, ob der aktuelle Inhalt der Zwischenablage in einem angegebenen Zwischenablage-Datenformat vorliegt, bevor Sie es Benutzern gestatten, die Informationen in das RichTextBox-Steuerelement einzufügen. Sie können z. B. einen Ereignishandler für ein Popup-Ereignis eines MenuItem für den Befehl zum Einfügen erstellen und mit dieser Methode bestimmen, ob das MenuItem zum Einfügen für den Datentyp in der Zwischenablage aktiviert werden soll.
Beispiel
Im folgenden Codebeispiel wird veranschaulicht, wie mit der Paste-Methode eine Bitmap in das RichTextBox-Steuerelement eingefügt wird. Nach dem Öffnen einer Bitmap aus einer Datei wird im Beispiel die SetDataObject-Methode verwendet, um die Bitmap in die Windows-Zwischenablage zu kopieren. Schließlich ruft das Beispiel das Format des Bitmap-Objekts ab, verwendet die CanPaste-Methode, um zu prüfen, ob das Format in das RichTextBox-Steuerelement eingefügt werden kann, und verwendet dann die Paste-Methode, um die Daten einzufügen.
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;
}
}
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
RichTextBox-Klasse
RichTextBox-Member
System.Windows.Forms-Namespace
Paste
DataFormats.Format-Klasse