Control.DoubleClick Evento

Definizione

Si verifica quando si fa doppio clic sul controllo.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 

Tipo evento

EventHandler

Esempio

Nell'esempio di codice seguente viene usato l' DoubleClick evento di un oggetto ListBox per caricare i file di testo elencati nell'oggetto in ListBox un TextBox controllo.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

Commenti

Un doppio clic è determinato dalle impostazioni del mouse del sistema operativo dell'utente.A double-click is determined by the mouse settings of the user's operating system. 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.The user can set the time between clicks of a mouse button that should be considered a double-click rather than two clicks. L' Click evento viene generato ogni volta che si fa doppio clic su un controllo.The Click event is raised every time a control is double-clicked. Se, ad esempio, si dispone di gestori eventi per Click gli DoubleClick eventi e di un Form , Click gli DoubleClick eventi e vengono generati quando si fa doppio clic sul form ed entrambi i metodi vengono chiamati.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. Se si fa doppio clic su un controllo e il controllo non supporta l' DoubleClick evento, è possibile che l' Click evento venga generato due volte.If a control is double-clicked and that control does not support the DoubleClick event, the Click event might be raised twice.

Per generare questo evento, è necessario impostare i StandardDoubleClick StandardClick valori e di ControlStyles su true .You must set the StandardDoubleClick and StandardClick values of ControlStyles to true for this event to be raised. Questi valori potrebbero essere già impostati su true se si ereditano da controlli di Windows Form esistenti.These values might already be set to true if you are inheriting from existing Windows Forms controls.

Nota

Gli eventi seguenti non vengono generati per la TabControl classe, a meno che non esista almeno un oggetto TabPage nella TabControl.TabPages raccolta: Click ,, DoubleClick MouseDown , MouseUp , MouseHover , MouseEnter MouseLeave e 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. Se è presente almeno un oggetto TabPage nella raccolta e l'utente interagisce con l'intestazione del controllo Tab (dove TabPage vengono visualizzati i nomi), TabControl genera l'evento appropriato.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. Tuttavia, se l'interazione dell'utente si trova all'interno dell'area client della pagina della scheda, TabPage genera l'evento appropriato.However, if the user interaction is within the client area of the tab page, the TabPage raises the appropriate event.

Per ulteriori informazioni sulla gestione degli eventi, consultare gestione e generazione di eventi.For more information about handling events, see Handling and Raising Events.

Note per gli eredi

Ereditare da un controllo Windows Form standard e modificare i StandardClick StandardDoubleClick valori o di ControlStyles in true può causare un comportamento imprevisto o non avere alcun effetto se il controllo non supporta gli Click DoubleClick eventi o.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.

Nella tabella seguente sono elencati Windows Form controlli e l'evento ( Click o DoubleClick ) generato in risposta all'azione del mouse specificata.The following table lists Windows Forms controls and which event (Click or DoubleClick) is raised in response to the mouse action specified.

ControlloControl Clic con il pulsante sinistro del mouseLeft Mouse Click Doppio clic con il pulsante sinistro del mouseLeft Mouse Double Click Clic con il pulsante destro del mouseRight Mouse Click Doppio clic con il pulsante destro del mouseRight Mouse Double Click Clic del mouse centraleMiddle Mouse Click Doppio clic con il mouseMiddle Mouse Double Click Clic del mouse XButton1XButton1 Mouse Click Double-Click del mouse XButton1XButton1 Mouse Double-Click Clic del mouse XButton2XButton2 Mouse Click Double-Click del mouse XButton2XButton2 Mouse Double-Click
MonthCalendar,MonthCalendar, DateTimePicker,DateTimePicker, RichTextBox,RichTextBox, HScrollBar,HScrollBar, VScrollBar Nessunonone Nessunonone Nessunonone Nessunonone Nessunonone Nessunonone Nessunonone Nessunonone Nessunonone Nessunonone
Button,Button, CheckBox,CheckBox, RadioButton Fare clic suClick Fare clic suClick, Click Nessunonone Nessunonone Nessunonone Nessunonone Nessunonone Nessunonone Nessunonone Nessunonone
ListBox,ListBox, CheckedListBox,CheckedListBox, ComboBox Fare clic suClick Fare clic su, DoubleClickClick, DoubleClick Nessunonone Nessunonone Nessunonone Nessunonone Nessunonone Nessunonone Nessunonone Nessunonone
TextBox,TextBox, DomainUpDown,DomainUpDown, NumericUpDown Fare clic suClick Fare clic su, DoubleClickClick, DoubleClick Nessunonone Nessunonone Nessunonone Nessunonone Nessunonone Nessunonone Nessunonone Nessunonone
\* TreeView,\* TreeView, \* ListView\* ListView Fare clic suClick Fare clic su, DoubleClickClick, DoubleClick Fare clic suClick Fare clic su, DoubleClickClick, DoubleClick Nessunonone Nessunonone Nessunonone Nessunonone Nessunonone Nessunonone
ProgressBar,ProgressBar, TrackBar Fare clic suClick Fare clic suClick, Click Fare clic suClick Fare clic suClick, Click Fare clic suClick Fare clic suClick, Click Fare clic suClick Fare clic suClick, Click Fare clic suClick Fare clic suClick, Click
Form,Form, DataGrid,DataGrid, Label,Label, LinkLabel,LinkLabel, Panel,Panel, GroupBox,GroupBox, PictureBox,PictureBox, Splitter,Splitter, StatusBar,StatusBar, ToolBar,ToolBar, TabPage,TabPage, ** TabControl Fare clic suClick Fare clic su, DoubleClickClick, DoubleClick Fare clic suClick Fare clic su, DoubleClickClick, DoubleClick Fare clic suClick Fare clic su, DoubleClickClick, DoubleClick Fare clic suClick Fare clic su, DoubleClickClick, DoubleClick Fare clic suClick Fare clic su, DoubleClickClick, DoubleClick

* Il puntatore del mouse deve essere posizionato su un oggetto figlio ( TreeNode o ListViewItem ).* The mouse pointer must be over a child object (TreeNode or ListViewItem).

* * Il TabControl deve avere almeno un TabPage nella relativa TabPages raccolta.** The TabControl must have at least one TabPage in its TabPages collection.

Si applica a

Vedi anche