Zooming in using Mouse Wheel

青春壹個敷衍的年華 提交于 2020-01-06 07:15:19

问题


So I have a graph, sometimes this graph goes up to 1000 in terms of the Y values and its far too hard to see individual points/axes interceptions.

This will allow me to click and drag an area to zoom in, however this ruins the X and Y values/intervals and also adds scrollbars to the graph which I do not want!

Chart1.ChartAreas(0).CursorX.IsUserSelectionEnabled = True
Chart1.ChartAreas(0).CursorY.IsUserSelectionEnabled = True

Is there a way to implement this using the mouse wheel and click to drag rather than using scrollbars?


回答1:


i found the answer in another question Enabling mouse wheel zooming in a Microsoft Chart Control

but it is in c# .. i converted it to vb.net

Private Sub growthChart_MouseEnter(sender As Object, e As EventArgs) Handles growthChart.MouseEnter
    growthChart.Focus()
End Sub


 Private Sub growthChart_MouseWheel(sender As Object, e As MouseEventArgs) Handles growthChart.MouseWheel
    Try
        With growthChart
            If (e.Delta < 0) Then
                .ChartAreas(0).AxisX.ScaleView.ZoomReset()
                .ChartAreas(0).AxisY.ScaleView.ZoomReset()
            End If

            If (e.Delta > 0) Then
                Dim xMin As Double = .ChartAreas(0).AxisX.ScaleView.ViewMinimum
                Dim xMax As Double = .ChartAreas(0).AxisX.ScaleView.ViewMaximum
                Dim yMin As Double = .ChartAreas(0).AxisY.ScaleView.ViewMinimum
                Dim yMax As Double = .ChartAreas(0).AxisY.ScaleView.ViewMaximum
                Dim posXStart As Double = (.ChartAreas(0).AxisX.PixelPositionToValue(e.Location.X) _
                            - ((xMax - xMin) _
                            / 4))
                Dim posXFinish As Double = (.ChartAreas(0).AxisX.PixelPositionToValue(e.Location.X) _
                            + ((xMax - xMin) _
                            / 4))
                Dim posYStart As Double = (.ChartAreas(0).AxisY.PixelPositionToValue(e.Location.Y) _
                            - ((yMax - yMin) _
                            / 4))
                Dim posYFinish As Double = (.ChartAreas(0).AxisY.PixelPositionToValue(e.Location.Y) _
                            + ((yMax - yMin) _
                            / 4))
                .ChartAreas(0).AxisX.ScaleView.Zoom(posXStart, posXFinish)
                .ChartAreas(0).AxisY.ScaleView.Zoom(posYStart, posYFinish)
            End If
        End With


    Catch ex As System.Exception
        MsgBox(ex.Message)
    End Try
End Sub

It worked well in zooming in but in zooming out it needs adjusting.



来源:https://stackoverflow.com/questions/21137104/zooming-in-using-mouse-wheel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!