问题
In my vb.net project, I use zedgraph to draw figures. I find that the following properties work well to zoom figure on the center of mouse.
Friend WithEvents gcMain As ZedGraph.ZedGraphControl
Me.gcMain.IsZoomOnMouseCenter = True
Me.gcMain.IsEnableWheelZoom = True
I have two toolstrip text boxes to show the minimum and maximum values of x axis. When I change values in text boxes, the x axis changes. The following code shows an example of handling the textbox. However I do not know how to update values in text boxes when the figure is zoomed by using IsEnableWheelZoom property. In zedgraph, ZedGraphControl_MouseWheel is a protected event.
Friend WithEvents tbxRangeStart As System.Windows.Forms.ToolStripTextBox
Private Sub tbxRangeStart_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tbxRangeStart.KeyDown
Try
If e.KeyCode = Keys.Enter Then
' Change x Axis here
End If
Catch
End Try
End Sub
回答1:
Use the ZoomEvent
:
chart.ZoomEvent += chart_ZoomEvent
...
private void chart_ZoomEvent(ZedGraphControl sender, ZoomState oldState, ZoomState newState)
{
textBoxMax.Text = chart.GraphPane.XAxis.Scale.Max.ToString();
textBoxMin.Text = chart.GraphPane.XAxis.Scale.Min.ToString();
}
回答2:
In vb.net, use following code
Private Sub gcMain_ZoomEvent(ByVal sender As ZedGraphControl, ByVal oldState As ZoomState, ByVal newState As ZoomState) Handles gcMain.ZoomEvent
'update text box here
End Sub
来源:https://stackoverflow.com/questions/8536325/zedgraph-enablewheelzoom-how-to-get-axis-values-after-zooming