Posted 22 October 2019, 11:41 pm EST
Hello,
MouseClick event fires for a control when mouse button is released on the control itself. This is the default behavior with MicroSoft controls also. If you click on the MS button then hold the mouse button and release it out of the button , MouseClick event will not fire but if you click on the button then hold the mouse button and move the cursor out of the button and then release it on the button itself, MouseClick event will fire.
In MS button case you can use MouseDown event but in C1Ribbon MouseDown event is not there so you need to handle it by the one of the following ways given below :
1 : Use MouseDown event of C1Ribbon as given in code snippet below :
private void C1Ribbon1_MouseDown(object sender, MouseEventArgs e)
{
var clickedElmnt = c1Ribbon1.HitTest(e.Location);
if (clickedElmnt != null && clickedElmnt.GetType().BaseType.Name == "ButtonElement")
{
if (c1Ribbon1.Bounds.Contains(clickedElmnt.Bounds))
{
MessageBox.Show("Ribbon button clicked");
}
}
}
2 : You can also use MouseLeave and MouseEnter event of RibbonButton to handle MouseDown event of C1Ribbon as given in code snippet below :
```
bool temp = true;
private void RibbonButton1_MouseLeave(object sender, EventArgs e)
{
temp = false;
}
private void RibbonButton1_MouseEnter(object sender, EventArgs e)
{
temp = true;
}
private void C1Ribbon1_MouseDown(object sender, MouseEventArgs e)
{
if (temp)
{
MessageBox.Show(“Ribbon button clicked”);
}
}
Please go through the attached sample demonstrating both the above given solutions.
Regards,
Prabhat Sharma.
[zip filename="RibbonButtonClick.zip"]https://gccontent.blob.core.windows.net/forum-uploads/file-7936e2ae-999d-482a-bdd4-07d0cef9418f.zip[/zip]