You can use AutoInteractionMode for the zooming and then use another helper class for panning with the right mouse button. One way that you can do this is by handling the MouseDown, MouseUp, and MouseMove events on the graph, determining how much the mouse has moved when the right mouse button is down, then use the graph's PanXY method to programmatically pan the graph. Below is a helper class called RightMouseButtonPan that will work with either the WaveformGraph or ScatterGraph. To use it in your project, create a class member variable for RightMouseButtonPan, then initialize it in your constructor after the InitializeComponent call, like this:
public class MyForm : Form
{
private RightMouseButtonPan _rightMouseButtonPan;
// This could be a ScatterGraph as well.
private NationalInstruments.UI.WindowsForms.WaveformGraph waveformGraph1;
// ...
public MyForm()
{
InitializeComponent();
_rightMouseButtonPan = new RightMouseButtonPan(waveformGraph1);
_rightMouseButtonPan.Enabled = true;
}
}
Once this is configured, you can right-click in the plot area of the graph and pan as long as the RightMouseButtonPan.Enabled property is true. To disable this behavior, set RightMouseButtonPan.Enabled to false. Hope this helps.
- Elton
private class RightMouseButtonPan
{
private bool _enabled;
private XYGraph _graph;
private bool _isPanning;
private Point _previousPoint;
public RightMouseButtonPan(XYGraph graph)
{
if (graph == null)
throw new ArgumentNullException("graph");
_enabled = false;
_graph = graph;
_isPanning = false;
_previousPoint = Point.Empty;
}
public bool Enabled
{
get
{
return _enabled;
}
set
{
if (value && !_enabled)
{
_graph.MouseDown += new MouseEventHandler(OnGraphMouseDown);
_graph.MouseMove += new MouseEventHandler(OnGraphMouseMove);
_graph.MouseUp += new MouseEventHandler(OnGraphMouseUp);
}
else if (!value && _enabled)
{
_graph.MouseDown -= new MouseEventHandler(OnGraphMouseDown);
_graph.MouseMove -= new MouseEventHandler(OnGraphMouseMove);
_graph.MouseUp -= new MouseEventHandler(OnGraphMouseUp);
}
_enabled = value;
}
}
private void OnGraphMouseDown(object sender, MouseEventArgs e)
{
Point currentPoint = new Point(e.X, e.Y);
if ((e.Button == MouseButtons.Right) && _graph.PlotAreaBounds.Contains(currentPoint))
{
_isPanning = true;
_previousPoint = new Point(e.X, e.Y);
_graph.Capture = true;
}
}
private void OnGraphMouseMove(object sender, MouseEventArgs e)
{
if (_isPanning)
{
Point currentPoint = new Point(e.X, e.Y);
float xFactor = (float)(_previousPoint.X - currentPoint.X) / _graph.PlotAreaBounds.Width;
float yFactor = (float)(currentPoint.Y - _previousPoint.Y) / _graph.PlotAreaBounds.Height;
_graph.PanXY(xFactor, yFactor);
_previousPoint = currentPoint;
}
}
private void OnGraphMouseUp(object sender, MouseEventArgs e)
{
if (_isPanning)
{
_isPanning = false;
_previousPoint = Point.Empty;
_graph.Capture = false;
}
}
}