Мое приложение выглядит так:
program.cs
using System;
using System.Windows.Forms;
namespace WindowsFormsClickAndDoubleClick
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
Form1.cs
using System.Windows.Forms;
namespace WindowsFormsClickAndDoubleClick
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void listView1_DoubleClick(object sender, EventArgs e)
{
MessageBox.Show("Double click");
}
private void listView1_Click(object sender, EventArgs e)
{
MessageBox.Show("Single click");
}
}
}
Form1.Designer.cs
namespace WindowsFormsClickAndDoubleClick
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem("one");
System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem("two");
this.listView1 = new System.Windows.Forms.ListView();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// listView1
//
this.listView1.HideSelection = false;
this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
listViewItem1,
listViewItem2,
});
this.listView1.Location = new System.Drawing.Point(97, 56);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(254, 134);
this.listView1.TabIndex = 1;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.List;
this.listView1.Click += new System.EventHandler(this.listView1_Click);
this.listView1.DoubleClick += new System.EventHandler(this.listView1_DoubleClick);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.listView1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.Timer timer1;
}
}
Я хочу обрабатывать как события щелчка, так и двойного щелчка, но я могу получить только сообщение о событии щелчка.