Control.DoubleClick Zdarzenie
Definicja
Występuje po dwukrotnym kliknięciu formantu.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
Typ zdarzenia
Przykłady
Poniższy przykład kodu używa DoubleClick zdarzenia ListBox do ładowania plików tekstowych wymienionych w ListBox TextBox kontrolce do formantu.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
Uwagi
Dwukrotnie kliknięcie konfiguruje się w ustawieniach myszy w systemie operacyjnym użytkownika.A double-click is determined by the mouse settings of the user's operating system. Użytkownik może ustawić czas między kliknięciami przycisku myszy, który powinien być uważany za dwukrotne kliknięcie, a nie dwoma kliknięciami.The user can set the time between clicks of a mouse button that should be considered a double-click rather than two clicks. ClickZdarzenie jest wywoływane za każdym razem, gdy formant zostanie kliknięty dwukrotnie.The Click event is raised every time a control is double-clicked. Na przykład jeśli masz programy obsługi zdarzeń dla Click DoubleClick zdarzeń i Form , Click DoubleClick zdarzenia i są wywoływane, gdy formularz zostanie dwukrotnie kliknięty i obie metody są wywoływane.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. Po dwukrotnym kliknięciu kontrolki, która nie obsługuje DoubleClick zdarzenia, Click zdarzenie może być wywoływane dwa razy.If a control is double-clicked and that control does not support the DoubleClick event, the Click event might be raised twice.
Należy ustawić StandardDoubleClick
StandardClick
wartości ControlStyles dla i true
dla tego zdarzenia, które ma zostać wywołane.You must set the StandardDoubleClick
and StandardClick
values of ControlStyles to true
for this event to be raised. Te wartości mogą być już ustawione na true
, Jeśli dziedziczą z istniejących kontrolek Windows Forms.These values might already be set to true
if you are inheriting from existing Windows Forms controls.
Uwaga
Następujące zdarzenia nie są wywoływane dla klasy, TabControl chyba że istnieje co najmniej jedna TabPage w TabControl.TabPages kolekcji:,,,,, Click DoubleClick MouseDown MouseUp MouseHover MouseEnter MouseLeave i MouseMove .The 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. Jeśli w kolekcji znajduje się co najmniej jeden TabPage , a użytkownik współdziała z nagłówkiem kontrolki karta (gdzie TabPage pojawiają się nazwy), TabControl wywołuje odpowiednie zdarzenie.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. Jeśli jednak interakcja użytkownika znajduje się w obszarze klienta strony karty, TabPage wywołuje odpowiednie zdarzenie.However, if the user interaction is within the client area of the tab page, the TabPage raises the appropriate event.
Aby uzyskać więcej informacji na temat obsługi zdarzeń, zobacz Obsługa iwywoływanie zdarzeń.For more information about handling events, see Handling and Raising Events.
Uwagi dotyczące dziedziczenia
Dziedziczenie ze standardowego formantu Windows Forms i zmiana StandardClick
StandardDoubleClick
wartości lub ControlStyles w celu true
może spowodować nieoczekiwane zachowanie lub nie wpływać na nie, jeśli formant nie obsługuje Click DoubleClick zdarzeń lub.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.
Poniższa tabela zawiera listę Windows Forms formantów i zdarzenia ( Click lub DoubleClick ), które są wywoływane w odpowiedzi na określoną akcję myszy.The following table lists Windows Forms controls and which event (Click or DoubleClick) is raised in response to the mouse action specified.
KontrolaControl | Kliknięcie lewym przyciskiem myszyLeft Mouse Click | Lewy dwukrotne kliknięcieLeft Mouse Double Click | Prawy przycisk myszyRight Mouse Click | Prawy przycisk dwukrotnego kliknięciaRight Mouse Double Click | Środkowy przycisk myszyMiddle Mouse Click | Środkowy prawy przycisk myszyMiddle Mouse Double Click | XButton1 kliknięcie myszyXButton1 Mouse Click | XButton1 Double-Click myszyXButton1 Mouse Double-Click | XButton2 kliknięcie myszyXButton2 Mouse Click | XButton2 Double-Click myszyXButton2 Mouse Double-Click |
---|---|---|---|---|---|---|---|---|---|---|
MonthCalendar,MonthCalendar, DateTimePicker,DateTimePicker, RichTextBox,RichTextBox, HScrollBar,HScrollBar, VScrollBar | braknone | braknone | braknone | braknone | braknone | braknone | braknone | braknone | braknone | braknone |
Button,Button, CheckBox,CheckBox, RadioButton | KliknijClick | Kliknij przycisk, kliknijClick, Click | braknone | braknone | braknone | braknone | braknone | braknone | braknone | braknone |
ListBox,ListBox, CheckedListBox,CheckedListBox, ComboBox | KliknijClick | Kliknij, kliknięcieClick, DoubleClick | braknone | braknone | braknone | braknone | braknone | braknone | braknone | braknone |
TextBox,TextBox, DomainUpDown,DomainUpDown, NumericUpDown | KliknijClick | Kliknij, kliknięcieClick, DoubleClick | braknone | braknone | braknone | braknone | braknone | braknone | braknone | braknone |
\* TreeView,\* TreeView, \* ListView\* ListView | KliknijClick | Kliknij, kliknięcieClick, DoubleClick | KliknijClick | Kliknij, kliknięcieClick, DoubleClick | braknone | braknone | braknone | braknone | braknone | braknone |
ProgressBar,ProgressBar, TrackBar | KliknijClick | Kliknij przycisk, kliknijClick, Click | KliknijClick | Kliknij przycisk, kliknijClick, Click | KliknijClick | Kliknij przycisk, kliknijClick, Click | KliknijClick | Kliknij przycisk, kliknijClick, Click | KliknijClick | Kliknij przycisk, kliknijClick, Click |
Form,Form, DataGrid,DataGrid, Label,Label, LinkLabel,LinkLabel, Panel,Panel, GroupBox,GroupBox, PictureBox,PictureBox, Splitter,Splitter, StatusBar,StatusBar, ToolBar,ToolBar, TabPage,TabPage, ** TabControl | KliknijClick | Kliknij, kliknięcieClick, DoubleClick | KliknijClick | Kliknij, kliknięcieClick, DoubleClick | KliknijClick | Kliknij, kliknięcieClick, DoubleClick | KliknijClick | Kliknij, kliknięcieClick, DoubleClick | KliknijClick | Kliknij, kliknięcieClick, DoubleClick |
* Wskaźnik myszy musi znajdować się nad obiektem podrzędnym ( TreeNode lub ListViewItem ).* The mouse pointer must be over a child object (TreeNode or ListViewItem).
* * TabControl Musi mieć co najmniej jeden TabPage w swojej TabPages kolekcji.** The TabControl must have at least one TabPage in its TabPages collection.