本文介绍了如何定位ContextMenuStrip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我似乎无法弄清楚如何将我的ContextMenuStrip放在dataGridViewCell下面。当我单击dataGridViewComboBoxCell时,我希望我的ContextMenuStrip显示在单元格的正下方。这就是我到目前为止所做的:
I can''t seem to figure out how to position my ContextMenuStrip below my dataGridViewCell. When I click the dataGridViewComboBoxCell I want my ContextMenuStrip to show right below the cell. Here''s what I''ve done so far:
class MyDropDownList : DataGridViewComboBoxCell
{
ContextMenuStrip dropDownList;
public MyDropDownList()
{
dropDownList = new ContextMenuStrip();
dropDownList.Items.Add("Hello World");
dropDownList.Items.Add("Goodbye");
dropDownList.Items.Add("Random stuff...");
}
protected override void OnMouseClick(DataGridViewCellMouseEventArgs e)
{
// ContextMenuStrip shows where the mouse
// was clicked within the cell area...
// I want the ContextMenuStrip to show
// right below the cell and to be aligned
// properly with the cell.
dropDownList.Show(Cursor.Position.X, Cursor.Position.Y);
// This wasn''t even close!
// dropDownList.Show(base.DataGridView.PointToScreen(e.Location));
}
}
所以基本上我希望ContextMenuStrip是行为是我的
DropDownList for dataGridViewComboBoxCell
So basically I want the ContextMenuStrip to is act is my
DropDownList for the dataGridViewComboBoxCell
推荐答案
protected override void OnMouseClick(DataGridViewCellMouseEventArgs e)
{
Rectangle rect = DataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
dropDownList.Show(DataGridView.PointToScreen(new Point(rect.Left, rect.Bottom)));
}
这篇关于如何定位ContextMenuStrip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!