Marker + Mouse_Up event

A forum dedicated to WinForms version of LightningChart Ultimate.

Moderator: Arction_LasseP

Post Reply
AnjaliIyengar
Posts: 6
Joined: Tue Jul 24, 2018 6:21 am

Marker + Mouse_Up event

Post by AnjaliIyengar » Mon Jun 03, 2019 10:16 am

Hi Team,

I am using ChartEventMarker. I attach events to it like "PositionChanged,MouseClick ". Both work. However MouseUp event is not fired at all. When should I expect the event to be fired? Why is it not triggering?

private void CreateChart()
{
// Disable rendering, strongly recommended before updating chart properties.
Chart.BeginUpdate();

Chart.Name = "PointLineSeries chart";

// Configure x-axis.
AxisX axisX = Chart.ViewXY.XAxes[0];
axisX.SetRange(0, 20);

// Configure y-axis.
Chart.ViewXY.YAxes[0].SetRange(0, 100);

PointShapeStyle symbol = new PointShapeStyle(
null,
Shape.Rectangle,
Color.Black,
Color.FromArgb(0, Color.Black),
Color.White,
Color.FromArgb(160, Color.Black),
3,
Chart.ViewXY.GetGraphSegmentInfo().GraphHeight - 30,
0,
0,
1,
GradientFillPoint.Solid,
Direction.None,
null);
//Marker on top of graph
ChartEventMarker chartMarker = new ChartEventMarker
{
XValue = 2,
Visible = true
};
chartMarker.Label.Text = "Marker";
chartMarker.Label.Color = Color.Black;
chartMarker.Label.VerticalAlign = AlignmentVertical.Top;
chartMarker.BindToXAxis = true;
chartMarker.Symbol = symbol;
chartMarker.Tag = 0;
chartMarker.MouseInteraction = true;
Chart.ViewXY.ChartEventMarkers.Add(chartMarker);
chartMarker.MouseUp += ChartMarker_MouseUp;
chartMarker.PositionChanged += ChartMarker_PositionChanged;

Chart.EndUpdate();
}

Arction_LasseP
Posts: 54
Joined: Wed Mar 27, 2019 1:05 pm

Re: Marker + Mouse_Up event

Post by Arction_LasseP » Mon Jun 03, 2019 12:35 pm

Hello,

We tested the events with ChartEventMarkers, but weren't able to reproduce this issue. At least PositionChanged, MouseClick, MouseDown and MouseUp -events were working correctly. MouseUp -event triggers the moment a mouse button is released. It then checks if the mouse is above the component, in this case the marker. So one reason why it might not trigger is that the mouse is not above the marker. This is easy to check if MoveByMouse -property is set false: press mouse button above the marker, move mouse away, release button. Do the same without moving the mouse away.

Here is an example code which adds a marker with working MouseUp -event:

Code: Select all

ChartEventMarker marker = new ChartEventMarker();
marker.MouseDown += Marker_MouseDown;
marker.MouseUp += Marker_MouseUp;
_chart.ViewXY.ChartEventMarkers.Add(marker);

private void Marker_MouseUp(object sender, MouseEventArgs e)
        {
            _chart.Title.Text = "Mouse up";
        }

private void Marker_MouseDown(object sender, MouseEventArgs e)
        {
            _chart.Title.Text = "Mouse down";
        }
If you are unable to get MouseUp -event to trigger, you can post us parts of your code where you define the marker and its events and we can try to find out what causes this issue.

AnjaliIyengar
Posts: 6
Joined: Tue Jul 24, 2018 6:21 am

Re: Marker + Mouse_Up event

Post by AnjaliIyengar » Mon Jun 03, 2019 2:30 pm

Hi Arction_LasseP,

Thank you for the reply. But 'MouseUp' event is not fired still. I use the version 8.2.1.4001 (Arction.WinForms.Charting.LightningChartUltimate)

(I made a sample project with just below lines of code.)
My code:
ChartEventMarker marker = new ChartEventMarker();
marker.MouseDown += Marker_MouseDown;
marker.MouseUp += ChartMarker_MouseUp;
marker.PositionChanged += ChartMarker_PositionChanged;
Chart.ViewXY.ChartEventMarkers.Add(marker);

private void ChartMarker_PositionChanged(object sender, PositionChangedChartEventMarkerEventArgs e)
{
Chart.Title.Text = "Position changed";
}

private void Marker_MouseDown(object sender, MouseEventArgs e)
{
Chart.Title.Text = "Mouse down";
}

private void ChartMarker_MouseUp(object sender, MouseEventArgs e)
{
Chart.Title.Text = "Mouse up";
}

It never comes to "ChartMarker_MouseUp". Are you using the same version? Please help! :?

Arction_LasseP
Posts: 54
Joined: Wed Mar 27, 2019 1:05 pm

Re: Marker + Mouse_Up event

Post by Arction_LasseP » Tue Jun 04, 2019 9:14 am

Hi,

I checked this again and found out that there is nothing wrong in your code, it is the LightningChart version that causes it. In some 8.2 versions MouseUp -event was bugged with some components such as annotations and event markers. This was fixed in later versions of LightningChart, which explains why it worked in my tests.

Therefore, I see two possible options to make the event work in your application:
1. Updating LightningChart to the newest version.
2. If the above is not an option, a workaround has to be used. One way is to use MouseUp -event for the chart component, which seems to work properly. It triggers whenever a mouse button is released as long as the chart has focus. You can use for example a boolean variable to make it to work with marker's MouseDown -event. Here is an example:

Code: Select all

private bool markerClicked = false;


ChartEventMarker marker = new ChartEventMarker();
marker.MouseDown += Marker_MouseDown;
_chart.ViewXY.ChartEventMarkers.Add(marker);

_chart.MouseUp += _chart_MouseUp;


private void Marker_MouseDown(object sender, MouseEventArgs e)
        {
            markerClicked = true;
        }

private void _chart_MouseUp(object sender, MouseEventArgs e)
        {
            if (markerClicked)
            {
                markerClicked = false;
                // Something happens
            }
        }
In this example whatever happens in MouseUp -event, is executed only if the marker is clicked first. One thing to note is that in this case the mouse cursor can be anywhere when the button is released (doesn't have to be above the marker).

Hope this helps.

AnjaliIyengar
Posts: 6
Joined: Tue Jul 24, 2018 6:21 am

Re: Marker + Mouse_Up event

Post by AnjaliIyengar » Tue Jun 04, 2019 10:25 am

Thank you :)

Post Reply