RichTextBox.CanPaste メソッド
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As RichTextBox Dim clipFormat As Format Dim returnValue As Boolean returnValue = instance.CanPaste(clipFormat)
- clipFormat
System.Windows.Forms.DataFormats.Format 値の 1 つ。
クリップボードのデータを指定したデータ形式で貼り付けできる場合は true。それ以外の場合は false。

このメソッドを使用すると、ユーザーがクリップボード内の情報を RichTextBox コントロールに貼り付けられるようにする前に、クリップボードの現在の内容が、指定されているクリップボード データ形式かどうかを確認できます。たとえば、貼り付けコマンドを表す MenuItem の Popup イベントを処理するイベント ハンドラを作成し、このメソッドを使用して、貼り付けコマンドを示す 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からRichTextBox.CanPaste メソッドを検索する場合は、下記のリンクをクリックしてください。

- RichTextBox.CanPaste メソッドのページへのリンク