Custom context menu plus dragging a chart

A forum dedicated to WinForms version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
Niels Decker
Posts: 12
Joined: Mon Nov 22, 2021 8:12 am

Custom context menu plus dragging a chart

Post by Niels Decker » Thu Mar 24, 2022 2:12 pm

Right-clicking (and keeping the right mouse button pressed) on a chart area allows me to drag the chart (surely a LightningChart functionality). When I add a WinForms ContextMenuStrip (plus several ToolStripMenuItems etc. as children) plus an event handler function, a right click opens that context menu, but now I am not able to use the drag function anymore.

Is there a way to use both, a custom context menu when I push the right mouse button, plus the drag function from LightningChart when I move the mouse while still having the right mouse button pressed?

Many thanks for help!
Niels

Niels Decker
Posts: 12
Joined: Mon Nov 22, 2021 8:12 am

Re: Custom context menu plus dragging a chart

Post by Niels Decker » Fri Mar 25, 2022 7:31 am

I thought about it again. The best would be a function like in windows file explorer: holding the right mouse button down on a file allows dragging the file, releasing the button opens the context menu. Transferred to LightningChart: holding the right mouse button down allows dragging, releasing the button opens my context menu.

Again: any help is highly appreciated!
Cheers
Niels

ArctionKestutis
Posts: 552
Joined: Mon Mar 14, 2016 9:22 am

Re: Custom context menu plus dragging a chart

Post by ArctionKestutis » Fri Mar 25, 2022 1:24 pm

Our Demo's ExampleAnnotationsXY has similar idea with Menu implementation. In that example menu is shown if MouseUp event occur above Annotation.
It is not difficult to keep mouse-right button dragging functionality on the chart and add "Menu showing functionality" on up event. Relevant WinForms code would be following:

Subscribe to chart.MouseUp event

Code: Select all

            chart.MouseUp += Chart_MouseUp;
And use something like this to show Menu:

Code: Select all

        private void Chart_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                //Show context menu for the annotation
                contextMenuStrip1.Show(_chart, e.X, e.Y);
            }
        }
By the way, with chart.ViewXY.ZoomPanOptions properties you can change which action (zoom, pan etc.) is associated with any mouse button.

Hope this helps.

Post Reply