We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

MouseDrag Zooming with Right Mouse Button

We have a WPF application using the chart control where we want to use the EnableMouseDragZooming feature, but we want it to be bound to the right mouse button instead of the left mouse button (we have some other custom logic bound to the left button). Does anybody know if this is possible?

We actually have a source code license and have modified the code for the chart to do this in the past (on v 8 of the controls) but we are now updating to the latest (v 12.1) and would like to avoid having to modify the source again. Is there a built-in way to support this, or can someone think of a way to achieve it through the public API without having to modify the chart control's source?

Thanks,
Kevin Kuebler

4 Replies

KV Karthikeyan V Syncfusion Team July 15, 2014 03:09 AM UTC

Hi kelvin,

Thanks for using the Syncfusion products.

We have analysed the reported query. We would like to inform you that the requirement achieved by workaround in sample. Please find the sample under the following location. And we do not have any public API to custom the left and right mouse sector zooming.

Please let us know if you require further assistance on this.

Thanks,

Karthikeyan V.


Attachment: ZoomingWithRightButton_b597fa05.zip


KK Kevin Kuebler July 15, 2014 01:44 PM UTC

Hi Karthikeyan,

Thank you for your response and the sample! The right mouse button drag/zooming behavior in the sample works perfectly. However, the left mouse button still invokes the zooming also. Is there a way to disable the left mouse button from invoking the zoom behavior while still using the right button as you have shown in the sample? I tried setting EnableMouseDragZooming = False, which had the effect of preventing the left button from zooming, while the right button would still draw the zoom rectangle but it would not actually invoke the zoom on mouse up.

The reason we want to do this is because we have our own custom behavior that we want to associate with the left mouse button. Thanks again for your help!

Kevin


KK Kevin Kuebler July 15, 2014 02:04 PM UTC

Okay, so I was able to make this work. I have the right mouse zooming behavior from your sample working while also disabling the standard left mouse button behavior. I did this by setting EnableMouseDragZooming to false on the control in the XAML, then in the MouseUp handler I set it to true right before calling ZoomSector.Execute then set it back to false right after the call. I also have to reset the start and end points after the zoom, otherwise a drag with the left button will invoke a zoom if the right button behavior has been used at least once. The code looks like this:

m_chartArea.EnableMouseDragZooming = true;
ChartAreaCommands.ZoomSector.Execute(rect, m_chartArea);
m_chartArea.EnableMouseDragZooming = false;
m_startZoomBarPoint = new Point();
m_endZoomBarPoint = new Point();

So, it's a bit of a hack, but it works. :-)  Let me know if there is a better way to do this, but if not this solution will work for me. Thanks!

Kevin


KV Karthikeyan V Syncfusion Team July 16, 2014 12:26 PM UTC

Hi Kelvin,

Thank for the update.

We have analysed the reported requirement. We have checked your code that the code is also best way to achieve your requirement. But we are suggesting one more solution for this requirement in below code. Please find the code snippet under the following location.

Code Snippet [C#]:

bool isLeftZooming = false;

 

private void area_MouseDown(object sender, MouseButtonEventArgs e)

{

        ChartArea area = sender as ChartArea;

        if (e.ChangedButton == MouseButton.Left && !area.AllowSegmentDragDrop)

        {

            area.AllowSegmentDragDrop = true;

            isLeftZooming = true;

        }

       …….

}

private void area_MouseMove(object sender, MouseEventArgs e)

{

       ChartArea area = sender as ChartArea;

       if (e.LeftButton == MouseButtonState.Pressed && isLeftZooming)

       {

            area.AllowSegmentDragDrop = false;

            isLeftZooming = false;

       }

………

} 

private void area_MouseUp(object sender, MouseButtonEventArgs e)

{

        ChartArea m_chartArea = sender as ChartArea;

        if (e.ChangedButton == MouseButton.Left)

        {

             isLeftZooming = false;

        }

…..

} 

Please let us know if you require further assistance on this.

Thanks,

Karthikeyan V.


Loader.
Live Chat Icon For mobile
Up arrow icon