Control.DoubleClick Událost

Definice

Nastane, když je ovládací prvek poklikání.

public:
 event EventHandler ^ DoubleClick;
public event EventHandler DoubleClick;
public event EventHandler? DoubleClick;
member this.DoubleClick : EventHandler 
Public Custom Event DoubleClick As EventHandler 

Event Type

Příklady

Následující příklad kódu používá DoubleClick událost načtení textových ListBox souborů uvedených v ListBox ovládacím TextBox prvku.

   // 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

Poznámky

Dvojité kliknutí je určeno nastavením myši operačního systému uživatele. Uživatel může nastavit čas mezi kliknutími tlačítka myši, který by se měl považovat za dvojité kliknutí, a ne dva kliknutí. Událost Click se vyvolá při každém poklikání ovládacího prvku. Pokud například máte obslužné rutiny událostí pro Click události a DoubleClick události Form, Click a DoubleClick události jsou vyvolány, když je formulář poklikání a obě metody jsou volány. Pokud je ovládací prvek poklikáním a tento ovládací prvek událost nepodporuje DoubleClick , Click může být událost vyvolána dvakrát.

Pro vyvolání této události je nutné nastavit StandardDoubleClick hodnoty a StandardClick hodnoty ControlStylestrue . Tyto hodnoty už můžou být nastavené na true, pokud dědíte z existujících ovládacích prvků model Windows Forms.

Note

Následující události nejsou vyvolány pro TabControl třídu, pokud v kolekci není alespoň jedna TabPageTabControl.TabPages: Click, , DoubleClickMouseDown, MouseUp, , MouseHover, MouseEnterMouseLeave a .MouseMove Pokud je v kolekci aspoň jedna TabPage a uživatel pracuje s záhlavím ovládacího prvku tab (kde TabPage se zobrazují jména), TabControl vyvolá příslušnou událost. Pokud je však interakce uživatele v klientské oblasti na stránce karty, TabPage vyvolá příslušnou událost.

Další informace o zpracování událostí naleznete v tématu Zpracování a vyvolávání událostí.

Poznámky pro dědice

Dědění ze standardního ovládacího prvku model Windows Forms a změna StandardClick nebo StandardDoubleClick hodnot ControlStyles na true může způsobit neočekávané chování nebo nemá žádný vliv, pokud ovládací prvek nepodporuje události Click nebo DoubleClick.

Následující tabulka uvádí model Windows Forms ovládací prvky a událost (Click nebo DoubleClick) je vyvolána v reakci na zadanou akci myši.

Řízení Kliknutí levým tlačítkem myši Levá myš poklikáním Kliknutí pravým tlačítkem myši Poklikání pravým tlačítkem myši Prostřední kliknutí myší Prostřední myš poklikáním Kliknutí myší XButton1 Double-Click myši XButton1 Kliknutí myší XButton2 Double-Click myši XButton2
MonthCalendar,

DateTimePicker,

RichTextBox,

HScrollBar,

VScrollBar

none

žádné žádné žádné žádné žádné žádné žádné žádné žádné
Button,

CheckBox,

RadioButton

Klikněte na

Klikněte, klikněte na žádné žádné žádné žádné žádné žádné žádné žádné
ListBox,

CheckedListBox,

ComboBox

Klikněte na

Click, DoubleClick žádné žádné žádné žádné žádné žádné žádné žádné
TextBox,

DomainUpDown,

NumericUpDown

Klikněte na

Click, DoubleClick žádné žádné žádné žádné žádné žádné žádné žádné
* TreeView,

* ListView

Klikněte na

Click, DoubleClick Klikněte na Click, DoubleClick žádné žádné žádné žádné žádné žádné
ProgressBar,

TrackBar

Klikněte na

Klikněte, klikněte na Klikněte na Klikněte, klikněte na Klikněte na Klikněte, klikněte na Klikněte na Klikněte, klikněte na Klikněte na Klikněte, klikněte na
Form,

DataGrid,

Label,

LinkLabel,

Panel,

GroupBox,

PictureBox,

Splitter,

StatusBar,

ToolBar,

TabPage,

** TabControl

Klikněte na

Click, DoubleClick Klikněte na Click, DoubleClick Klikněte na Click, DoubleClick Klikněte na Click, DoubleClick Klikněte na Click, DoubleClick

* Ukazatel myši musí být nad podřízeným objektem (TreeNode nebo ListViewItem).

** Musí TabControl mít v kolekci TabPage alespoň jednuTabPages.

Platí pro

Viz také