private void NavigateChart(ScrollableControlBase chart) { if (chart == null || !chart.Created) { return; } Size size = chart.ContentSize; Rectangle viewPort = chart.DisplayRectangle; if (FullRectangle.Width > ViewRectangle.Width) { if (FullRectangle.X >= ViewRectangle.X) { chart.SetScrollValue(ScrollBars.Horizontal, 0, true); } else if (FullRectangle.Right <= ViewRectangle.Right) { chart.SetScrollValue(ScrollBars.Horizontal, size.Width - viewPort.Width, true); } else { chart.SetScrollValue(ScrollBars.Horizontal, (ViewRectangle.X - FullRectangle.X) * size.Width / FullRectangle.Width, true); } } if (FullRectangle.Height > ViewRectangle.Height) { if (FullRectangle.Y >= ViewRectangle.Y) { chart.SetScrollValue(ScrollBars.Vertical, 0, true); } else if (FullRectangle.Bottom <= ViewRectangle.Bottom) { chart.SetScrollValue(ScrollBars.Vertical, size.Height - viewPort.Height, true); } else { chart.SetScrollValue(ScrollBars.Vertical, (ViewRectangle.Y - FullRectangle.Y) * size.Height / FullRectangle.Height, true); } } }
void OnChartChanged(ScrollableControlBase old) { if (old != null) { old.ContentSizeChanged -= Chart_ContentSizeChanged; old.HScrollValueChanged -= Chart_HScrollValueChanged; old.VScrollValueChanged -= Chart_VScrollValueChanged; old.ViewUpdated -= Chart_ViewUpdated; } if (Chart != null) { Chart.ContentSizeChanged += Chart_ContentSizeChanged; Chart.HScrollValueChanged += Chart_HScrollValueChanged; Chart.VScrollValueChanged += Chart_VScrollValueChanged; Chart.ViewUpdated += Chart_ViewUpdated; } InvalidateRanges(); InvalidateMap(); }