Clipboard.GetDataObject メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Clipboard.GetDataObject メソッドの意味・解説 

Clipboard.GetDataObject メソッド

現在システム クリップボードにあるデータ取得します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Shared Function GetDataObject
 As IDataObject
Dim returnValue As IDataObject

returnValue = Clipboard.GetDataObject
public static IDataObject GetDataObject ()
public:
static IDataObject^ GetDataObject ()
public static IDataObject GetDataObject ()
public static function GetDataObject
 () : IDataObject

戻り値
現在クリップボード格納されているデータを表す IDataObject。データクリップボード格納されていない場合null 参照 (Visual Basic では Nothing)。

例外例外
解説解説
使用例使用例

Clipboardメソッド使用してシステム クリップボードデータ貼り付けたりシステム クリップボードからデータ取得したりするコード例次に示します。このコードは、button1button2textBox1、および textBox2フォーム上に配置されていることを前提にしています。

button1_Click メソッドは、SetDataObject を呼び出してテキスト ボックス内で選択されているテキスト取り出しシステム クリップボード貼り付けます。

button2_Click メソッドは、GetDataObject呼び出してシステム クリップボードからデータ取得しますコードは、IDataObject と DataFormats を使用して返されデータ抽出します。抽出したデータtextBox2表示されます。

Private Sub button1_Click(sender As
 Object, e As System.EventArgs)
    ' Takes the selected text from a text box and puts it on the clipboard.
    If textBox1.SelectedText <> ""
 Then
        Clipboard.SetDataObject(textBox1.SelectedText)
    Else
        textBox2.Text = "No text selected in textBox1"
    End If
End Sub 'button1_Click
 
Private Sub button2_Click(sender As
 Object, e As System.EventArgs)
    ' Declares an IDataObject to hold the data returned from the clipboard.
    ' Retrieves the data from the clipboard.
    Dim iData As IDataObject = Clipboard.GetDataObject()
    
    ' Determines whether the data is in a format you can use.
    If iData.GetDataPresent(DataFormats.Text) Then
        ' Yes it is, so display it in a text box.
        textBox2.Text = CType(iData.GetData(DataFormats.Text), String)
    Else
        ' No it is not.
        textBox2.Text = "Could not retrieve data off the clipboard."
    End If
End Sub 'button2_Click
private void button1_Click(object sender, System.EventArgs
 e) {
    // Takes the selected text from a text box and puts it on the clipboard.
    if(textBox1.SelectedText != "")
       Clipboard.SetDataObject(textBox1.SelectedText);
    else
       textBox2.Text = "No text selected in textBox1";
 }
 
 private void button2_Click(object sender,
 System.EventArgs e) {
    // Declares an IDataObject to hold the data returned from the clipboard.
    // Retrieves the data from the clipboard.
    IDataObject iData = Clipboard.GetDataObject();
 
    // Determines whether the data is in a format you can use.
    if(iData.GetDataPresent(DataFormats.Text)) {
       // Yes it is, so display it in a text box.
       textBox2.Text = (String)iData.GetData(DataFormats.Text); 
    }
    else {
       // No it is not.
       textBox2.Text = "Could not retrieve data off the clipboard.";
    }
 }
 
private:
   void button1_Click( Object^ /*sender*/, System::EventArgs^
 /*e*/ )
   {
      // Takes the selected text from a text box and puts it on the
 clipboard.
      if ( !textBox1->SelectedText->Equals( ""
 ) )
      {
         Clipboard::SetDataObject( textBox1->SelectedText );
      }
      else
      {
         textBox2->Text = "No text selected in textBox1";
      }
   }

   void button2_Click( Object^ /*sender*/, System::EventArgs^
 /*e*/ )
   {
      // Declares an IDataObject to hold the data returned from the
 clipboard.
      // Retrieves the data from the clipboard.
      IDataObject^ iData = Clipboard::GetDataObject();
      
      // Determines whether the data is in a format you can use.
      if ( iData->GetDataPresent( DataFormats::Text ) )
      {
         // Yes it is, so display it in a text box.
         textBox2->Text = (String^)(iData->GetData( DataFormats::Text ));
      }
      else
      {
         // No it is not.
         textBox2->Text = "Could not retrieve data off the clipboard.";
      }
   }
private void button1_Click(Object sender, System.EventArgs
 e)
{
    // Takes the selected text from a text box and puts it on the clipboard.
    if (!textBox1.get_SelectedText().Equals("")) {
        Clipboard.SetDataObject(textBox1.get_SelectedText());
    }
    else {
        textBox2.set_Text("No text selected in textBox1");
    }
} //button1_Click

private void button2_Click(Object sender, System.EventArgs
 e)
{
    // Declares an IDataObject to hold the data returned from the clipboard.
    // Retrieves the data from the clipboard.
    IDataObject iData = Clipboard.GetDataObject();

    // Determines whether the data is in a format you can use.
    if (iData.GetDataPresent(DataFormats.Text)) {
        // Yes it is, so display it in a text box.
        textBox2.set_Text((String)(iData.GetData(DataFormats.Text)));
    }
    else {
        // No it is not.
        textBox2.set_Text("Could not retrieve data off the clipboard.");
    }
} //button2_Click
private function button1_Click(sender : Object,
 e : System.EventArgs) {
    //Take the selected text from a text box and put it on the clipboard.
    if(textBox1.SelectedText != "")
       Clipboard.SetDataObject(textBox1.SelectedText);
    else
       textBox2.Text = "No text selected in textBox1";
 }
 
 private function button2_Click(sender : Object,
 e : System.EventArgs) {
    //Declare an IDataObject to hold the data returned from the clipboard.
    //Then retrieve the data from the clipboard.
    var iData : IDataObject = Clipboard.GetDataObject();
 
    //Determine whether the data is in a format you can use.
    if(iData.GetDataPresent(DataFormats.Text)) {
       //Yes it is, so display it in a text box.
       textBox2.Text = String(iData.GetData(DataFormats.Text)); 
    }
    else {
       //No it is not.
       textBox2.Text = "Could not retrieve data off the clipboard.";
    }
 }
 
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Clipboard.GetDataObject メソッド」の関連用語

Clipboard.GetDataObject メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Clipboard.GetDataObject メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS