Control.DoubleClick イベント

定義

コントロールがダブルクリックされたときに発生します。

public:
 event EventHandler ^ DoubleClick;
public event EventHandler DoubleClick;
public event EventHandler? DoubleClick;
member this.DoubleClick : EventHandler 
Public Custom Event DoubleClick As EventHandler 

イベントの種類

次のコード例では、 の イベントをDoubleClick使用して、 にリストされているテキスト ファイルをListBoxコントロールにTextBox読み込ListBoxみます。

   // 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.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 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

注釈

ダブルクリックは、ユーザーのオペレーティング システムのマウス設定によって決まります。 ユーザーは、2 回のクリックではなくダブルクリックと見なされるマウス ボタンのクリック間隔を設定できます。 イベントは Click 、コントロールがダブルクリックされるたびに発生します。 たとえば、 の イベントと DoubleClick イベントのClickFormイベント ハンドラーClickがある場合、 および DoubleClick イベントは、フォームがダブルクリックされ、両方のメソッドが呼び出されたときに発生します。 コントロールがダブルクリックされ、そのコントロールがイベントを DoubleClick サポートしていない場合、イベントが Click 2 回発生する可能性があります。

このイベントを発生させるには、 StandardDoubleClickStandardClickControlStyles 値を に true 設定する必要があります。 既存のWindows フォーム コントロールから継承する場合、これらの値は既に にtrue設定されている可能性があります。

注意

コレクション内に少なくとも 1 つTabPageがある場合をTabControl除き、 クラスにTabControl.TabPages対して、、DoubleClickMouseDownMouseEnterMouseUpMouseHoverMouseLeaveおよび MouseMoveのイベントは発生しません。 Click コレクションに少なくとも 1 つ TabPage があり、ユーザーがタブ コントロールのヘッダー (名前が表示される場所) と対話する TabPage 場合、 TabControl は適切なイベントを発生させます。 ただし、ユーザー操作がタブ ページのクライアント領域内にある場合は、 TabPage によって適切なイベントが発生します。

イベントの処理の詳細については、「処理とイベントの発生」を参照してください。

注意 (継承者)

標準のWindows フォーム コントロールから継承し、 または StandardDoubleClickControlStyles値を にtrue変更StandardClickすると、予期しない動作が発生する可能性があります。コントロールが または DoubleClick イベントをClickサポートしていない場合は、まったく影響を及ぼすことはありません。

次の表に、Windows フォームコントロールと、指定されたマウス アクションに応答して発生するイベント (Click または DoubleClick) を示します。

コントロール マウスの左クリック マウスの左クリック マウスの右クリック マウスの右クリック マウスの中央クリック マウスの中央クリック XButton1 マウス クリック XButton1 マウス Double-Click XButton2 マウス クリック XButton2 マウス Double-Click
MonthCalendar,

DateTimePicker,

RichTextBox,

HScrollBar,

VScrollBar

なし なし なし なし なし なし なし なし なし なし
Button,

CheckBox,

RadioButton

Click クリック、クリック なし なし なし なし なし なし なし なし
ListBox,

CheckedListBox,

ComboBox

Click Click、DoubleClick なし なし なし なし なし なし なし なし
TextBox,

DomainUpDown,

NumericUpDown

Click Click、DoubleClick なし なし なし なし なし なし なし なし
* TreeView,

* ListView

Click Click、DoubleClick Click Click、DoubleClick なし なし なし なし なし なし
ProgressBar,

TrackBar

Click クリック、クリック Click クリック、クリック Click クリック、クリック Click クリック、クリック Click クリック、クリック
Form,

DataGrid,

Label,

LinkLabel,

Panel,

GroupBox,

PictureBox,

Splitter,

StatusBar,

ToolBar,

TabPage,

** TabControl

Click Click、DoubleClick Click Click、DoubleClick Click Click、DoubleClick Click Click、DoubleClick Click Click、DoubleClick

* マウス ポインターは、子オブジェクト (TreeNode または ListViewItem) の上に置く必要があります。

** コレクション TabControl には少なくとも 1 つ TabPageTabPages 含む必要があります。

適用対象

こちらもご覧ください