クリップボードの情報を指定したデータ形式で貼り付けできるかどうかを確認します。
Public Function CanPaste( _
ByVal clipFormat As DataFormats.Format _) As Boolean
[C#]
public bool CanPaste(DataFormats.FormatclipFormat);
[C++]
public: bool CanPaste(DataFormats.Format* clipFormat);
[JScript]
public function CanPaste(
clipFormat : DataFormats.Format) : Boolean;
パラメータ
- clipFormat
System.Windows.Forms.DataFormats.Format 値の 1 つ。
戻り値
クリップボードのデータを指定したデータ形式で貼り付けできる場合は true 。それ以外の場合は false 。
解説
このメソッドを使用すると、クリップボード内の現在の内容が、指定されているクリップボード データ形式かどうかを確認してから、ユーザーがクリップボード内の情報を RichTextBox コントロールに貼り付けできるようにすることが可能です。たとえば、貼り付けコマンドを表す MenuItem の Popup イベントを処理するイベント ハンドラを作成し、このメソッドを使用して、貼り付けコマンドを示す MenuItem を有効にするかどうかをクリップボード内のデータの型に基づいて判断します。
使用例
[Visual Basic, C#, C++] 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
[C#]
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;
}
}
[C++]
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(S"The data format that you attempted to paste is not supported by this control.");
return false;
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
RichTextBox クラス | RichTextBox メンバ | System.Windows.Forms 名前空間 | Paste | System.Windows.Forms.DataFormats.Format