Control.DoubleClick Control.DoubleClick Control.DoubleClick Control.DoubleClick Event

定义

在双击控件时发生。Occurs when the control is double-clicked.

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

示例

下面的DoubleClick代码示例使用的事件ListBox将中TextBox列出的ListBox文本文件加载到控件中。The following code example uses the DoubleClick event of a ListBox to load text files listed in the ListBox into a TextBox control.

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

注解

双击由用户操作系统的鼠标设置确定。A double-click is determined by the mouse settings of the user's operating system. 用户可以设置两次单击鼠标按钮之间的时间以便将这两次单击认为是双击而不是两次单击。The user can set the time between clicks of a mouse button that should be considered a double-click rather than two clicks. Click次双击控件时都会引发该事件。The Click event is raised every time a control is double-clicked. 例如,如果有的ClickDoubleClick事件Form的事件处理程序,则在双击窗Click体并调用这两个方法时,将引发和DoubleClick事件。For example, if you have event handlers for the Click and DoubleClick events of a Form, the Click and DoubleClick events are raised when the form is double-clicked and both methods are called. 如果双击控件,而该控件不支持DoubleClick该事件,则可能会引发此Click事件两次。If a control is double-clicked and that control does not support the DoubleClick event, the Click event might be raised twice.

若要引发此StandardDoubleClick事件,必须ControlStylestrue的和StandardClick值设置为。You must set the StandardDoubleClick and StandardClick values of ControlStyles to true for this event to be raised. 如果要从现有 Windows 窗体控件继承true ,则这些值可能已设置为。These values might already be set to true if you are inheriting from existing Windows Forms controls.

备注

不会为TabControl类引发以下事件,除非TabControl.TabPages集合中至少有一个TabPageClickDoubleClickMouseDownMouseUp MouseHover MouseEnter、、、MouseLeave和。MouseMoveThe following events are not raised for the TabControl class unless there is at least one TabPage in the TabControl.TabPages collection: Click, DoubleClick, MouseDown, MouseUp, MouseHover, MouseEnter, MouseLeave and MouseMove. 如果集合中至少有一个TabPage ,并且用户与选项卡控件的标头(其中显示了TabPage名称)交互,则TabControl会引发相应的事件。If there is at least one TabPage in the collection, and the user interacts with the tab control's header (where the TabPage names appear), the TabControl raises the appropriate event. 但是,如果用户交互位于选项卡页的工作区中,则TabPage会引发相应的事件。However, if the user interaction is within the client area of the tab page, the TabPage raises the appropriate event.

有关处理事件的详细信息, 请参阅处理和引发事件For more information about handling events, see Handling and Raising Events.

继承者说明

如果控件不StandardClick支持ClickStandardDoubleClick true ControlStyles ,则从标准Windows窗体控件继承并将的或值更改为可能会导致意外行为或根本不起作用。DoubleClick事件。Inheriting from a standard Windows Forms control and changing the StandardClick or StandardDoubleClick values of ControlStyles to true can cause unexpected behavior or have no effect at all if the control does not support the Click or DoubleClick events.

下表列出 Windows 窗体控件以及为响应指定的Click鼠标DoubleClick操作而引发的事件(或)。The following table lists Windows Forms controls and which event (Click or DoubleClick) is raised in response to the mouse action specified.

控件Control 单击鼠标左键Left Mouse Click 双击鼠标左键Left Mouse Double Click 鼠标右键单击Right Mouse Click 右键单击鼠标右键Right Mouse Double Click 鼠标中键单击Middle Mouse Click 双击鼠标中键Middle Mouse Double Click XButton1 鼠标单击XButton1 Mouse Click XButton1 鼠标双击XButton1 Mouse Double-Click XButton2 鼠标单击XButton2 Mouse Click XButton2 鼠标双击XButton2 Mouse Double-Click
MonthCalendar,MonthCalendar, DateTimePicker,DateTimePicker, RichTextBox,RichTextBox, HScrollBar,HScrollBar, VScrollBar none none none none none none none none none none
Button,Button, CheckBox,CheckBox, RadioButton 单击Click 单击,单击Click, Click none none none none none none none none
ListBox,ListBox, CheckedListBox,CheckedListBox, ComboBox 单击Click 单击,DoubleClickClick, DoubleClick none none none none none none none none
TextBox,TextBox, DomainUpDown,DomainUpDown, NumericUpDown 单击Click 单击,DoubleClickClick, DoubleClick none none none none none none none none
\* TreeView,\* TreeView, \* ListView\* ListView 单击Click 单击,DoubleClickClick, DoubleClick 单击Click 单击,DoubleClickClick, DoubleClick none none none none none none
ProgressBar,ProgressBar, TrackBar 单击Click 单击,单击Click, Click 单击Click 单击,单击Click, Click 单击Click 单击,单击Click, Click 单击Click 单击,单击Click, Click 单击Click 单击,单击Click, Click
Form,Form, DataGrid,DataGrid, Label,Label, LinkLabel,LinkLabel, Panel,Panel, GroupBox,GroupBox, PictureBox,PictureBox, Splitter,Splitter, StatusBar,StatusBar, ToolBar,ToolBar, TabPage,TabPage, ** TabControl 单击Click 单击,DoubleClickClick, DoubleClick 单击Click 单击,DoubleClickClick, DoubleClick 单击Click 单击,DoubleClickClick, DoubleClick 单击Click 单击,DoubleClickClick, DoubleClick 单击Click 单击,DoubleClickClick, DoubleClick

*鼠标指针必须位于子对象(TreeNodeListViewItem)上。* The mouse pointer must be over a child object (TreeNode or ListViewItem).

* * TabControl在其TabPages集合中必须至少TabPage有一个。** The TabControl must have at least one TabPage in its TabPages collection.

适用于

另请参阅