Right mouse click on propertyGridControl not working
I am handling both events Click and MouseClick on propertyGridControl but when I click with right button nothing happens - it catches only left.
private void propertyGridControl_Click(object sender, EventArgs e)
{
int i = 0;
if (e.Button == System开发者_StackOverflow中文版.Windows.Forms.MouseButtons.Right)
{
MessageBox.Show("right");
}
}
How to catch right mouse click?
I have checked how the MouseClick event works and do not see this issue. The event is correctly raised. I've checked 10.2.5 (latest version) of the PropertyGridControl. I can only imagine that you are clicking inside the grid's editor. In this case, mouse and keyboard events are managed by the in-place editor and not the grid. To catch this event, you may use the following code:
private void propertyGridControl1_ShownEditor(object sender, EventArgs e) {
PropertyGridControl pgc = sender as PropertyGridControl;
pgc.ActiveEditor.MouseClick -= new MouseEventHandler(ActiveEditor_MouseClick);
pgc.ActiveEditor.MouseClick += new MouseEventHandler(ActiveEditor_MouseClick);
}
void ActiveEditor_MouseClick(object sender, MouseEventArgs e) {
if(e.Button == System.Windows.Forms.MouseButtons.Right) {
MessageBox.Show("right");
}
}
I have just one more idea. If the control's ContextMenuStrip property is set, the MouseClick event is not raised if the right mouse button is pressed. Is it your case? The solution is easy - handle the control's MouseDown event.
精彩评论