這是我的代碼:
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
如您所見,我設定了一個函式,當用戶單擊串列視圖時呼叫它,但它僅在您單擊串列視圖中的文本時才起作用。當您單擊控制元件內的任意位置時,如何使其呼叫該函式?
uj5u.com熱心網友回復:
使用事件mousedown檢測整個串列視圖中的點擊
添加mousedown事件
listView1.MouseDown = ListView1_MouseDown;
執行
private void ListView1_MouseDown(object sender, MouseEventArgs e)
{
throw new NotImplementedException();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/365591.html
上一篇:winforms識別符號不可見
下一篇:如何修復應用程式退出(Winforms)時的“System.Threading.Tasks.TaskCanceledException:'Ataskwascancelled.'”例
