为什么 c# winforms ListView.Click 事件处理程序仅在您单击列表视图中包含的文本而不是整个控件中时才起作用?
Why does c# winforms ListView.Click event handler only work when you click on the text contained in the list view and not in the whole of the control?
这是我的代码:
ListView listview = new ListView();
listview.Size = new System.Drawing.Size(150, 100);
listview.BackColor = System.Drawing.Color.Orange;
listview.ForeColor = System.Drawing.Color.Black;
listview.Name = "Group" + count2;
listview.FullRowSelect = true; // just tried this
listview.Click += HighLight;
// no Position is set because its added to a FlowLayoutPanel
foreach (var item in text_list)
{
listview.Items.Add(item); // adds the text
}
autolayoutGroups.Controls.Add(listview); // add to FlowlayoutPanel
如您所见,我设置了一个函数,当用户单击列表视图时将调用该函数,但它仅在您单击列表视图中的文本时才起作用。如何让它在您单击控件中的任意位置时调用该函数?
使用事件mousedown
检测整个listview
中的点击
添加mousedown
事件
listView1.MouseDown += ListView1_MouseDown;
实施
private void ListView1_MouseDown(object sender, MouseEventArgs e)
{
throw new NotImplementedException();
}
这是我的代码:
ListView listview = new ListView();
listview.Size = new System.Drawing.Size(150, 100);
listview.BackColor = System.Drawing.Color.Orange;
listview.ForeColor = System.Drawing.Color.Black;
listview.Name = "Group" + count2;
listview.FullRowSelect = true; // just tried this
listview.Click += HighLight;
// no Position is set because its added to a FlowLayoutPanel
foreach (var item in text_list)
{
listview.Items.Add(item); // adds the text
}
autolayoutGroups.Controls.Add(listview); // add to FlowlayoutPanel
如您所见,我设置了一个函数,当用户单击列表视图时将调用该函数,但它仅在您单击列表视图中的文本时才起作用。如何让它在您单击控件中的任意位置时调用该函数?
使用事件mousedown
检测整个listview
添加mousedown
事件
listView1.MouseDown += ListView1_MouseDown;
实施
private void ListView1_MouseDown(object sender, MouseEventArgs e)
{
throw new NotImplementedException();
}