Jump to content
Software FX Community

Implementing a custom zoom using mouse events handlers


Recommended Posts

I am trying to implement a custom zoom solution for ChartFX, and the code looks something like this:



private Point startPoint = Point.Empty;

// On mouse down, save the starting point
void chart_MouseDownEvent(object sender, _ChartEvents_MouseDownEvent e)
{
startPoint = new Point(e.args.X, e.args.Y);
}

// On mouse up, zoom to coordinates
void chart_MouseUpEvent(object sender, _ChartEvents_MouseUpEvent e)
{
if (e.args.Button != ButtonLeft)
  return;

// override regular functionality
e.args.Handled = true;

Point endPoint = new Point(e.args.X, e.args.Y);

Axis xAxis = chart.AxisX;
Axis yAxis = chart.AxisY;

double minX = xAxis.PixelToValue(startPoint.X);
double maxX = xAxis.PixelToValue(endPoint.X);

double minY = yAxis.PixelToValue(startPoint.Y);
double maxY = yAxis.PixelToValue(endPoint.Y);

if (!axChart1.Zoom)
axChart1.Zoom = true;

xAxis.Zoom(Math.Min(minX, maxX), Math.Max(minX, maxX));
yAxis.Zoom(Math.Min(minY, maxY), Math.Max(minY, maxY));
}



The problem is that, after I handle the event, zoom selection dashed rectangle remains visible (and active as I move the mouse). I bypassed the standard functionality (I did set the Handled property to true), but it seems like it still remains in this "in-the-middle-of-zoom" mode.


Does anyone have any experience with implementing custom zoom functionality? Maybe someone has encountered this before.


Thanks a lot!

Link to post
Share on other sites

By setting:

e.args.Handled = true;

You are preventing everything that was going to be done on that event from executing. In this case this includes clearing the flag that says the selection rectangle is vissible.

In order to make this work, you also set the Handled property to true in the MouseDown event and handle the draing of the selection rectangle in your MouseMove/PostPaint event handlers.

Another option is that instead of zooming-in right away when you get the call to MouseUp, let the library take its course and perform the regular zoom, then by using a timer or a PostBack message thta gets fired on MouseUp, adjust it according to your needs.

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...