Control.DoubleClick Událost

Definice

Vyvolá se při poklikání na ovládací prvek.

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 objektu ListBox k načtení textových souborů uvedených v souboru ListBox do TextBox ovládacího 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

Poklepání je určeno nastavením myši v operačním systému uživatele. Uživatel může nastavit dobu mezi kliknutím na tlačítko myši, která by měla být považována za dvojité kliknutí místo dvou kliknutí. Událost Click se vyvolá při každém poklikání na ovládací prvek. Pokud například máte obslužné rutiny událostí pro Click události a DoubleClick objektu Form, Click události a DoubleClick jsou vyvolány při poklikání na formulář a obě metody jsou volány. Pokud je na ovládací prvek poklikání a tento ovládací prvek nepodporuje DoubleClick událost, Click může být událost vyvolána dvakrát.

Aby se tato událost vyvolala, musíte nastavit StandardDoubleClick hodnoty ControlStylestrue a StandardClick na hodnotu . 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.

Poznámka

Následující události se pro TabControl třídu nevyvolají, pokud není v TabControl.TabPages kolekci alespoň jednaTabPage: Click, DoubleClick, , MouseDown, MouseUpMouseHover, MouseEnter, MouseLeave a MouseMove. Pokud je v kolekci alespoň jedna TabPage a uživatel pracuje s záhlavím ovládacího prvku karta (kde TabPage se zobrazují názvy), TabControl vyvolá příslušná událost. Pokud je však interakce uživatele v klientské oblasti stránky karty, TabPage vyvolá příslušnou událost.

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

Poznámky pro dědice

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

Následující tabulka obsahuje seznam model Windows Forms ovládacích prvků a událost (Click nebo DoubleClick) vyvolaná v reakci na zadanou akci myši.

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

DateTimePicker,

RichTextBox,

HScrollBar,

VScrollBar

žádné žá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 alespoň jeden TabPage objekt ve své kolekci TabPages .

Platí pro

Viz také