Control.DoubleClick 事件

在双击控件时发生。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Event DoubleClick As EventHandler
用法
Dim instance As Control
Dim handler As EventHandler

AddHandler instance.DoubleClick, handler
public event EventHandler DoubleClick
public:
event EventHandler^ DoubleClick {
    void add (EventHandler^ value);
    void remove (EventHandler^ value);
}
/** @event */
public void add_DoubleClick (EventHandler value)

/** @event */
public void remove_DoubleClick (EventHandler value)
JScript 支持使用事件,但不支持进行新的声明。

备注

双击操作由用户操作系统的鼠标设置确定。用户可以设置两次单击鼠标按钮之间的时间以便将这两次单击认为是双击而不是两次单击。每当双击控件时,就会引发 Click 事件。例如,如果您有 FormClickDoubleClick 事件的事件处理程序,则当双击该窗体并同时调用这两个方法时,会引发 ClickDoubleClick 事件。如果双击一个控件并且该控件不支持 DoubleClick 事件,则 Click 事件可能被引发两次。

若要引发该事件,必须将 ControlStylesStandardDoubleClickStandardClick 值设置为 true。如果当前是从现有的 Windows 窗体控件中继承,这些值可能已设置为 true

提示

除非 TabControl.TabPages 集合中至少有一个 TabPage,否则不会引发 TabControl 类的下列事件:ClickDoubleClickMouseDownMouseUpMouseHoverMouseEnterMouseLeaveMouseMove。如果集合中至少有一个 TabPage,并且用户与选项卡控件标头(显示 TabPage 名称的地方)交互,则 TabControl 将引发相应的事件。但是,如果用户交互发生在选项卡页的工作区内,则 TabPage 将引发相应的事件。

有关处理事件的更多信息,请参见 使用事件

给继承者的说明 如果标准 Windows 窗体控件不支持 ClickDoubleClick 事件,则从该控件继承并将 ControlStylesStandardClickStandardDoubleClick 值更改为 true 会导致意外的行为,或者根本不会产生任何效果。 下表列出 Windows 窗体控件及指定的鼠标操作会引发哪个事件(Click 还是 DoubleClick)。

控件

Left Mouse Click

Left Mouse Double Click

Right Mouse Click

Right Mouse Double Click

Middle Mouse Click

Middle Mouse Double Click

XButton1 Mouse Click

XButton1 Mouse Double-Click

XButton2 Mouse Click

XButton2 Mouse Double-Click

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

* 鼠标指针必须位于子对象上(TreeNodeListViewItem)。 TabControlTabPages 集合中必须至少有一个 TabPage

示例

下面的代码示例使用 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

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0

请参见

参考

Control 类
Control 成员
System.Windows.Forms 命名空间
OnDoubleClick
StandardClick
StandardDoubleClick
Control.Click 事件
MouseClick
MouseDoubleClick