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

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

Control.OnDoubleClick メソッド

DoubleClick イベント発生させます

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

Protected Overridable Sub
 OnDoubleClick ( _
    e As EventArgs _
)
Dim e As EventArgs

Me.OnDoubleClick(e)
protected virtual void OnDoubleClick (
    EventArgs e
)
protected:
virtual void OnDoubleClick (
    EventArgs^ e
)
protected void OnDoubleClick (
    EventArgs e
)
protected function OnDoubleClick (
    e : EventArgs
)

パラメータ

e

イベント データ格納している EventArgs。

解説解説
使用例使用例

ListBoxDoubleClick イベント使用してListBox に示すテキスト ファイルTextBox コントロール読み込むコード例次に示します

' This example uses the DoubleClick event of a ListBox to load text
 files  
' listed in the ListBox into a TextBox control. This example
' assumes that the ListBox, named listBox1, contains a list of valid
 file 
' names with path and that this event handler method
' is connected to the DoublClick event of a ListBox control named listBox1.
' This example requires code access permission to access files.
Private Sub listBox1_DoubleClick(ByVal
 sender As Object, ByVal
 e As System.EventArgs) Handles listBox1.DoubleClick
    ' Get the name of the file to open from the ListBox.
    Dim file As [String] = listBox1.SelectedItem.ToString()

    Try
        ' Determine if the file exists before loading.
        If System.IO.File.Exists(file) Then
            ' Open the file and use a TextReader to read the contents
 into the TextBox.
            Dim myFile As New
 System.IO.FileInfo(listBox1.SelectedItem.ToString())
            Dim myData As System.IO.TextReader
 = myFile.OpenText()

            textBox1.Text = myData.ReadToEnd()
            myData.Close()
        End If
        ' Exception is thrown by the OpenText method of the FileInfo
 class.
    Catch
        MessageBox.Show("The file you specified does not exist.")
        ' Exception is thrown by the ReadToEnd method of the TextReader
 class.
    Catch
     MessageBox.Show("There was a problem loading the file into
 the TextBox. Ensure that the file is a valid text file.")
    End Try
End Sub
// This example uses the DoubleClick event of a ListBox to load text
 files
// listed in the ListBox into a TextBox control. This example
// assumes that the ListBox, named listBox1, contains a list of valid
 file
// names with path and that this event handler method
// is connected to the DoublClick event of a ListBox control named listBox1.
// This example requires code access permission to access files.
private void listBox1_DoubleClick(object sender,
 System.EventArgs e)
{
    // Get the name of the file to open from the ListBox.
    String file = listBox1.SelectedItem.ToString();

    try
    {
        // Determine if the file exists before loading.
        if (System.IO.File.Exists(file))
        {
            // Open the file and use a TextReader to read the contents
 into the TextBox.
            System.IO.FileInfo myFile = new System.IO.FileInfo(listBox1.SelectedItem.ToString());
            System.IO.TextReader myData = myFile.OpenText();;

            textBox1.Text = myData.ReadToEnd();
            myData.Close();
        }
    }
        // Exception is thrown by the OpenText method of the FileInfo
 class.
    catch(System.IO.FileNotFoundException)
    {
        MessageBox.Show("The file you specified does not exist.");
    }
        // Exception is thrown by the ReadToEnd method of the TextReader
 class.
    catch(System.IO.IOException)
    {
        MessageBox.Show("There was a problem loading the file into the TextBox.
 Ensure that the file is a valid text file.");
    }
}
   // This example uses the DoubleClick event of a ListBox to load text
 files
   // listed in the ListBox into a TextBox control. This example
   // assumes that the ListBox, named listBox1, contains a list of valid
 file
   // names with path and that this event handler method
   // is connected to the DoublClick event of a ListBox control named
 listBox1.
   // This example requires code access permission to access files.
private:
   void listBox1_DoubleClick( Object^ /*sender*/, System::EventArgs^
 /*e*/ )
   {
      // Get the name of the file to open from the ListBox.
      String^ file = listBox1->SelectedItem->ToString();
      try
      {
         // Determine if the file exists before loading.
         if ( System::IO::File::Exists( file ) )
         {
            
            // Open the file and use a TextReader to read the contents
 into the TextBox.
            System::IO::FileInfo^ myFile = gcnew System::IO::FileInfo( listBox1->SelectedItem->ToString()
 );
            System::IO::TextReader^ myData = myFile->OpenText();
            ;
            textBox1->Text = myData->ReadToEnd();
            myData->Close();
         }
      }
      // Exception is thrown by the OpenText method of the FileInfo
 class.
      catch ( System::IO::FileNotFoundException^ ) 
      {
         MessageBox::Show( "The file you specified does not exist." );
      }
      // Exception is thrown by the ReadToEnd method of the TextReader
 class.
      catch ( System::IO::IOException^ ) 
      {
         MessageBox::Show( "There was a problem loading the file into the TextBox.
 Ensure that the file is a valid text file." );
      }
   }
// This example uses the DoubleClick event of a ListBox to load text
 files
// listed in the ListBox into a TextBox control. This example
// assumes that the ListBox, named listBox1, contains a list of valid
 file
// names with path and that this event handler method
// is connected to the DoublClick event of a ListBox control named listBox1.
// This example requires code access permission to access files.
private void listBox1_DoubleClick(Object sender,
 System.EventArgs e)
{
    // Get the name of the file to open from the ListBox.
    String file = listBox1.get_SelectedItem().ToString();
    try {
        // Determine if the file exists before loading.
        if (System.IO.File.Exists(file)) {
            // Open the file and use a TextReader to read the contents
 
            // into the TextBox.
            System.IO.FileInfo myFile = new System.IO.FileInfo(listBox1.
                get_SelectedItem().ToString());
            System.IO.TextReader myData = myFile.OpenText();
            textBox1.set_Text(myData.ReadToEnd());
            myData.Close();
        }
    }
    // Exception is thrown by the OpenText method of the FileInfo class.
    catch (System.IO.FileNotFoundException exp) {
        MessageBox.Show("The file you specified does not exist.");
    }
    // Exception is thrown by the ReadToEnd method of the TextReader
 class.
    catch (System.IO.IOException exp) {
        MessageBox.Show("There was a problem loading the file into the "
            + "TextBox. Ensure that the file is a valid text file.");
    }
} //listBox1_DoubleClick
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からControl.OnDoubleClick メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からControl.OnDoubleClick メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からControl.OnDoubleClick メソッド を検索

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

辞書ショートカット

すべての辞書の索引

「Control.OnDoubleClick メソッド」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS