ZedGraph 源码修改 选择X轴放大
通过修改源码实现 图谱区域选择区域缩放,X轴可以实现选中区域横向缩放
1.在ZedGraphControl 类中增加 _isXSelectZoom 属性,用来标识是否选择X轴坐标
- 在 MasterPane 类中增加 FindXPaneRect 方法用于查找X坐标轴具体区域,此方法也可以直接改为返回bool 仅用于验证
/// <summary>
/// 查找X轴空白
/// </summary>
/// <param name="mousePt"></param>
/// <returns></returns>
public GraphPane FindXPaneRect(PointF mousePt)
{
foreach (GraphPane pane in _paneList)
{
double chartX= pane.Chart._rect.X;
double startChartY = pane.Chart._rect.Y+ pane.Chart._rect.Height;
if (mousePt.Y > startChartY)
return pane;
}
return null;
}
3.在ZedGraphControl.Events 类中 ZedGraphControl_MouseDown事件中修改代码如下
- 在ZedGraphControl.Events 类中CalcScreenRect 方法中 修改如下代码,控制选择区域虚线矩形显示问题
private Rectangle CalcScreenRect( Point mousePt1, Point mousePt2 )
{
Point screenPt = PointToScreen( mousePt1 );
Size size = new Size( mousePt2.X - mousePt1.X, mousePt2.Y - mousePt1.Y );
Rectangle rect = new Rectangle( screenPt, size );
if ( _isZooming )
{
Rectangle chartRect = Rectangle.Round( _dragPane.Chart._rect );
Point chartPt = PointToScreen( chartRect.Location );
if ( !_isEnableVZoom || _isXSelectZoom)
{
rect.Y = chartPt.Y;
rect.Height = chartRect.Height + 1;
}
else if ( !_isEnableHZoom )
{
rect.X = chartPt.X;
rect.Width = chartRect.Width + 1;
}
}
return rect;
}
5.修改 ZedGraphControl.Events 类中HandleZoomFinish 方法