Control.DoubleClick Evento
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Si verifica quando si fa doppio clic sul controllo.
public:
event EventHandler ^ DoubleClick;
public event EventHandler DoubleClick;
member this.DoubleClick : EventHandler
Public Custom Event DoubleClick As EventHandler
Tipo evento
Esempio
Nell'esempio di codice seguente viene utilizzato l'evento DoubleClick di un ListBox oggetto per caricare i file di testo elencati in ListBox in un TextBox controllo .
// 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
Commenti
Un doppio clic è determinato dalle impostazioni del mouse del sistema operativo dell'utente. L'utente può impostare il tempo tra i clic di un pulsante del mouse che deve essere considerato un doppio clic anziché due clic. L'evento Click viene generato ogni volta che viene fatto doppio clic su un controllo. Ad esempio, se si dispone di gestori eventi per gli Click eventi e di un Form, gli Click eventi e DoubleClickDoubleClick vengono generati quando il form viene fatto doppio clic e vengono chiamati entrambi i metodi. Se si fa doppio clic su un controllo e tale controllo non supporta l'evento DoubleClick , l'evento Click potrebbe essere generato due volte.
È necessario impostare i StandardDoubleClick valori e StandardClick di su true per la generazione di ControlStyles questo evento. Questi valori potrebbero essere già impostati su true se si eredita da controlli di Windows Forms esistenti.
Note
Gli eventi seguenti non vengono generati per la TabControl classe a meno che non sia presente almeno uno TabPage nell'insiemeTabControl.TabPages: Click, DoubleClick, MouseDownMouseUp, MouseHover, MouseEnter, MouseLeave e MouseMove. Se nella raccolta è presente almeno uno TabPage e l'utente interagisce con l'intestazione del controllo struttura a schede (dove vengono visualizzati i TabPage nomi), genera TabControl l'evento appropriato. Tuttavia, se l'interazione dell'utente si trova all'interno dell'area client della pagina della scheda, genera TabPage l'evento appropriato.
Per ulteriori informazioni sulla gestione degli eventi, consultare gestione e generazione di eventi.
Note per gli eredi
Ereditando da un controllo Windows Forms standard e modificando i valori StandardClick o StandardDoubleClick di valori di ControlStyles in true può causare comportamenti imprevisti o non avere alcun effetto se il controllo non supporta gli eventi Click o DoubleClick.
Nella tabella seguente sono elencati Windows Forms controlli e quale evento (Click o DoubleClick) viene generato in risposta all'azione del mouse specificata.
| Controllo | Clic con il mouse sinistro | Doppio clic con il mouse sinistro | Clic con il pulsante destro del mouse | Doppio clic del mouse con il pulsante destro del mouse | Clic centrale del mouse | Doppio clic del mouse centrale | Clic del mouse su XButton1 | Double-Click mouse XButton1 | Clic del mouse su XButton2 | Double-Click mouse XButton2 |
|---|---|---|---|---|---|---|---|---|---|---|
| MonthCalendar, | none | nessuno | nessuno | nessuno | nessuno | nessuno | nessuno | nessuno | nessuno | nessuno |
| Button, | Fare clic su | Fare clic, fare clic su | nessuno | nessuno | nessuno | nessuno | nessuno | nessuno | nessuno | nessuno |
| ListBox, | Fare clic su | Fare clic su DoubleClick | nessuno | nessuno | nessuno | nessuno | nessuno | nessuno | nessuno | nessuno |
| TextBox, | Fare clic su | Fare clic su DoubleClick | nessuno | nessuno | nessuno | nessuno | nessuno | nessuno | nessuno | nessuno |
|
*
TreeView, * ListView | Fare clic su | Fare clic su DoubleClick | Fare clic su | Fare clic su DoubleClick | nessuno | nessuno | nessuno | nessuno | nessuno | nessuno |
| ProgressBar, | Fare clic su | Fare clic, fare clic su | Fare clic su | Fare clic, fare clic su | Fare clic su | Fare clic, fare clic su | Fare clic su | Fare clic, fare clic su | Fare clic su | Fare clic, fare clic su |
|
Form,
** TabControl | Fare clic su | Fare clic su DoubleClick | Fare clic su | Fare clic su DoubleClick | Fare clic su | Fare clic su DoubleClick | Fare clic su | Fare clic su DoubleClick | Fare clic su | Fare clic su DoubleClick |
* Il puntatore del mouse deve essere posizionato su un oggetto figlio (TreeNode o ListViewItem).
** L'oggetto TabControl deve avere almeno un TabPage oggetto nella raccolta TabPages .