本文介绍了使用鼠标滚轮放大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有一个图,有时该图的Y值上升到1000,而且很难看到单个点/轴的截距。
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.
这将允许我单击并拖动区域以进行放大,但是这会破坏X和Y值/间隔,并且还会向图形添加滚动条,而我不这样做
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?
推荐答案
我找到了另一个问题
但是它在c#中。我将其转换为vb.net
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.
这篇关于使用鼠标滚轮放大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!