c#中contextMenuStrip与datagridview使用CellMouseDown事件及treeview使用mousedown事件
?//對于datagridview使用CellMouseDown事件
private void dataGridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)?
{?
if (e.Button == MouseButtons.Right)?
{?
?? if (e.RowIndex >= 0)?
?? {?
??? dataGridView.ClearSelection();?
??? dataGridView.Rows[e.RowIndex].Selected = true;?
??? dataGridView.CurrentCell = dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex];?
??? contextMenuStrip_ListViewItemRightClick.Show(MousePosition.X, MousePosition.Y);?
?? }?
}?
}
//對于treeview可以使用mousedown事件
方法一:
private void treeView1_MouseDown(object sender, MouseEventArgs e)?
{?
if (e.Button == MouseButtons.Right)?
{?
TreeNode node = this.treeView1.GetNodeAt(e.Location);?
if (node != null)?
{?
this.treeView1.SelectedNode = node;?
}?
}?
}
方法二:
void?jcsTreeView1_MouseDown(object?sender, MouseEventArgs e)
??????? {
?????????? System.Windows.Forms.TreeViewHitTestInfo hittestinfo?=?this.jcsTreeView1.HitTest(e.X ,e.Y);
???????????if?(hittestinfo.Node?!=?null)
?????????? {
?????????????? TreeViewHitTestLocations loc?=?hittestinfo.Location;
???????????????if(loc?==?TreeViewHitTestLocations.Label )
???????????????? MessageBox.Show(hittestinfo.Node.Text);
?????????? }
??????? }
轉載于:https://www.cnblogs.com/jose/archive/2011/09/06/2168601.html
總結
以上是生活随笔為你收集整理的c#中contextMenuStrip与datagridview使用CellMouseDown事件及treeview使用mousedown事件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: su的时候密码认证失败的解决方法
- 下一篇: C# 4.0 新特性之参数