Control.DoubleClick イベント

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

Public Event DoubleClick As EventHandler
[C#]
public event EventHandler DoubleClick;
[C++]
public: __event EventHandler* DoubleClick;

[JScript] JScript では、このクラスで定義されているイベントを処理できます。ただし、独自に定義することはできません。

イベント データ

イベント ハンドラが EventArgs 型の引数を受け取りました。

解説

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

このイベントを発生させるには、 ControlStyles.StandardDoubleClick ビットおよび ControlStyles.StandardClick ビットを true に設定する必要があります。既存の Windows フォーム コントロールから継承している場合、これらのビットは既に true に設定されていることがあります。

継承時の注意: 標準の Windows フォーム コントロールから継承し、 StandardClick ビット値または StandardDoubleClick ビット値を true に変更すると、コントロールが Click イベントまたは DoubleClick イベントをサポートしていない場合は、予測できない動作が行われたり、何の効果も得られなかったりします。

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

コントロール 左マウス クリック 左マウス ダブルクリック 右マウス クリック 右マウス ダブルクリック 中央マウス クリック 中央マウス ダブルクリック XButton1 マウス クリック XButton1 マウス ダブルクリック XButton2 マウス クリック XButton2 マウス ダブルクリック
MonthCalendar,

DateTimePicker,

RichTextBox,

HScrollBar,

VScrollBar

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

CheckBox,

RadioButton

Click Click, 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, Click Click Click, Click Click 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 には、 TabPages コレクション内に少なくとも 1 つの TabPage が必要です。

メモ    ClickDoubleClickMouseDownMouseUpMouseHoverMouseEnterMouseLeaveMouseMove の各イベントは、 TabControl.TabPages コレクションに 1 つ以上の TabPage が存在しない限り、 TabControl クラスで生成されません。コレクションに 1 つ以上の TabPage があり、ユーザーがタブ コントロールのヘッダー (TabPage の名前が表示される場所) と対話すると、 TabControl が適切なイベントを発生させます。ただし、ユーザーとの対話がタブ ページのクライアント領域内の場合、 TabPage は該当するイベントを発生させます。

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

使用例

 
' 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 handling 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

[C#] 
// 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 handling 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.");
    }
}

[C++] 
// 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 handling 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(S"The file you specified does not exist.");
   }
   // Exception is thrown by the ReadToEnd method of the TextReader class.
   catch(System::IO::IOException*)
   {
      MessageBox::Show(S"There was a problem loading the file into the TextBox. Ensure that the file is a valid text file.");
   }
}

[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 ファミリ

参照

Control クラス | Control メンバ | System.Windows.Forms 名前空間 | OnDoubleClick | StandardClick | StandardDoubleClick