Control.DoubleClick Evento

Definizione

Si verifica quando si fa doppio clic sul controllo.

public:
 event EventHandler ^ DoubleClick;
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 usato l'evento DoubleClick di un ListBox oggetto per caricare i file di testo elencati in ListBox 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 un intervallo tra i clic effettuati con un pulsante del mouse in modo che debbano essere considerati come un doppio clic anziché come due clic distinti. L'evento Click viene generato ogni volta che viene fatto doppio clic su un controllo. Ad esempio, se sono presenti gestori eventi per gli Click eventi e di un Formoggetto , gli Click eventi e DoubleClickDoubleClick vengono generati quando il modulo viene fatto doppio clic e vengono chiamati entrambi i metodi. Se un controllo viene fatto doppio clic e tale controllo non supporta l'evento, l'evento DoubleClickClick potrebbe essere generato due volte.

È necessario impostare i valori e StandardClick di ControlStyles su true per l'evento StandardDoubleClick da creare. Questi valori potrebbero essere già impostati su true se si eredita dai controlli di Windows Forms esistenti.

Nota

Gli eventi seguenti non vengono generati per la classe, a meno che non sia presente almeno uno nell'insieme TabControlTabControl.TabPages: Click, MouseDownMouseHoverDoubleClickMouseUpMouseEnterMouseLeave e .MouseMoveTabPage Se nella raccolta è presente almeno uno TabPage e l'utente interagisce con l'intestazione del controllo tabulazioni (in cui 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 StandardClick valori o StandardDoubleClick da ControlStylestrue può causare un comportamento imprevisto o non avere alcun effetto se il controllo non supporta gli Click eventi oDoubleClick.

La tabella seguente elenca Windows Forms controlli e quale evento (Clicko DoubleClick) viene generato in risposta all'azione del mouse specificata.

Controllo Fare clic sul mouse a sinistra Fare doppio clic sul mouse a sinistra Fare clic con il mouse con il pulsante destro del mouse Fare doppio clic con il mouse con il pulsante destro del mouse Fare clic sul mouse centrale Doppio clic sul mouse centrale Fare clic su XButton1 Mouse Double-Click mouse XButton1 Fare clic su XButton2 Mouse Double-Click mouse XButton2
MonthCalendar,

DateTimePicker,

RichTextBox,

HScrollBar,

VScrollBar

Nessuno Nessuno Nessuno Nessuno Nessuno Nessuno Nessuno Nessuno Nessuno Nessuno
Button,

CheckBox,

RadioButton

Fare clic su Fare clic, fare clic su Nessuno Nessuno Nessuno Nessuno Nessuno Nessuno Nessuno Nessuno
ListBox,

CheckedListBox,

ComboBox

Fare clic su Fare clic su DoubleClick Nessuno Nessuno Nessuno Nessuno Nessuno Nessuno Nessuno Nessuno
TextBox,

DomainUpDown,

NumericUpDown

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,

TrackBar

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,

DataGrid,

Label,

LinkLabel,

Panel,

GroupBox,

PictureBox,

Splitter,

StatusBar,

ToolBar,

TabPage,

** 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 su un oggetto figlio (TreeNode o ListViewItem).

** Deve TabControl avere almeno uno TabPage nella raccolta TabPages .

Si applica a

Vedi anche