Control.DoubleClick 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在双击控件时发生。
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
注解
双击由用户操作系统的鼠标设置决定。 用户可以设置两次单击鼠标按钮之间的时间以便将这两次单击认为是双击而不是两次单击。 Click每次双击控件时都会引发 事件。 例如,如果具有 的 Click 和 DoubleClick 事件的Form事件处理程序,DoubleClickClick则双击窗体并调用这两种方法时,将引发 和 事件。 如果双击某个控件,并且该控件不支持该 DoubleClick 事件,则可能会引发该 Click 事件两次。
必须将 的 ControlStylestrue
和 StandardClick
值设置为 StandardDoubleClick
,才能引发此事件。 如果要从现有Windows 窗体控件继承,则这些值可能已设置为 true
。
注意
除非集合中至少有一个TabPage事件,否则不会为 TabControl 类引发以下事件:Click、、DoubleClick、MouseDownMouseUp、MouseHover、 MouseEnterMouseLeave 和 MouseMove。TabControl.TabPages 如果集合中至少有一个 TabPage ,并且用户与选项卡控件的标头交互 (TabPage 名称显示在) ,则会 TabControl 引发相应的事件。 但是,如果用户交互位于选项卡页的工作区内, TabPage 将引发相应的事件。
有关处理事件的详细信息,请参阅 处理和引发事件。
继承者说明
从标准Windows 窗体控件继承并将 的 或 值更改为 StandardClick
true
可能会导致意外行为,或者如果控件不支持 Click 或 DoubleClick 事件,则根本不起作用。StandardDoubleClick
ControlStyles
下表列出了Windows 窗体控件,以及为响应指定的鼠标操作而引发 (或DoubleClick) 的事件Click。
控制 | 鼠标左键单击 | 鼠标左键双击 | 鼠标右键单击 | 鼠标右键双击 | 鼠标中键单击 | 鼠标中双击 | XButton1 鼠标单击 | XButton1 鼠标Double-Click | XButton2 鼠标单击 | XButton2 鼠标Double-Click |
---|---|---|---|---|---|---|---|---|---|---|
MonthCalendar, | 无 | 无 | 无 | 无 | 无 | 无 | 无 | 无 | 无 | 无 |
Button, | 单击 | 单击,单击 | 无 | 无 | 无 | 无 | 无 | 无 | 无 | 无 |
ListBox, | 单击 | 单击,DoubleClick | 无 | 无 | 无 | 无 | 无 | 无 | 无 | 无 |
TextBox, | 单击 | 单击,DoubleClick | 无 | 无 | 无 | 无 | 无 | 无 | 无 | 无 |
*
TreeView, * ListView | 单击 | 单击,DoubleClick | 单击 | 单击,DoubleClick | 无 | 无 | 无 | 无 | 无 | 无 |
ProgressBar, | 单击 | 单击,单击 | 单击 | 单击,单击 | 单击 | 单击,单击 | 单击 | 单击,单击 | 单击 | 单击,单击 |
Form,
** TabControl | 单击 | 单击,DoubleClick | 单击 | 单击,DoubleClick | 单击 | 单击,DoubleClick | 单击 | 单击,DoubleClick | 单击 | 单击,DoubleClick |
* 鼠标指针必须位于子对象 (TreeNode 或 ListViewItem) 上。
** 集合TabControlTabPages中必须至少有一个TabPage。