问题描述
Dim pointMove As New Point
Dim ukazovatko As Boolean = False
Private Sub Chart1_MouseMove(ByVal sender As Object,ByVal e As MouseEventArgs) Handles Chart1.MouseMove
If ukazovatko Then
pointMove = New Point(e.X,e.Y)
Label1.Location = New Point(e.X + Label1.Size.Width / 2,Chart1.Bottom)
Label1.Text = Math.Round(Chart1.ChartAreas(0).AxisX.PixelPositionTovalue(e.X),2)
End If
End Sub
Private Sub Label1_Paint(ByVal sender As Object,ByVal e As PaintEventArgs) Handles Label1.Paint
ControlPaint.DrawBorder(e.Graphics,Label1.displayRectangle,Color.Red,ButtonBorderStyle.solid)
End Sub
Private Sub Chart1_MouseClick(ByVal sender As Object,ByVal e As MouseEventArgs) Handles Chart1.MouseClick
ukazovatko = Not ukazovatko
End Sub
Private Sub Chart1_Paint(ByVal sender As Object,ByVal e As PaintEventArgs) Handles Chart1.Paint
Chart1.Invalidate()
Dim g As Graphics = e.Graphics
Dim p As New Pen(Color.Red,2)
g.DrawLine(p,pointMove.X,Chart1.Size.Height)
End Sub
在我的test application中它可以正常工作。当我将代码复制粘贴到another application中时,它崩溃了。我发现它甚至无法识别Chart.MouseClick事件。我以为问题可能出在tabControl,但我不知道如何处理。当然,在此问题之前,我已经进行了研究,但似乎我是唯一遇到过此类问题的人(:D)。我还要提到我是编程的初学者,所以我可能对此有些非常明显的解决方案有所了解。
解决方法
最后,我完全无奈地试图重新组织代码,然后将图表代码移至最底部,并以某种方式对其进行了修复。