来自子例程的MouseEventArgs

时间:2017-04-03 09:35:32

标签: vb.net charts mouseevent paint

我在Visual Studio 2013中有一个图表,我可以使用MouseventArgs处理程序在其上绘制一条线。不用担心。

但....你怎么能有一个单独的子程序,然后使用鼠标事件绘制一条线。我需要的是如果我按下一个按钮,画一条线,如果我没有按下按钮则使用常规的mouseventargs。

所以按钮需要启动它:

enter code herePrivate Sub Chart1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles chD.MouseDown
    FirstPoint = New Point(e.X, e.Y)
    TempPoint = New Point(e.X, e.Y)
End Sub

Private Sub Chart1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles chD.MouseMove
    If Not FirstPoint = Nothing Then
        Dim g As Graphics = chD.CreateGraphics
        Dim ErasePen As Pen = New Pen(Me.BackColor)
        g.DrawLine(ErasePen, FirstPoint, TempPoint)
        TempPoint = New Point(e.X, e.Y)
        Me.Refresh()
    End If

End Sub

Private Sub Chart1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles chD.MouseUp

    Dim Line As New LineEndPoints With {.StartPoint = FirstPoint, .endPont = New Point(e.X, e.Y)}
    LinesList.Add(Line)
    FirstPoint = Nothing
    Me.Refresh()

End Sub

Private Sub Chart1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles chD.Paint

    For Each line As LineEndPoints In LinesList
        e.Graphics.DrawLine(Pens.Yellow, line.StartPoint, line.endPont)
    Next
    If Not FirstPoint = Nothing Then
        e.Graphics.DrawLine(Pens.Yellow, FirstPoint, TempPoint)
    End If

End Sub`

` 有谁知道我怎么能做到这一点?

0 个答案:

没有答案