2012-03-08 54 views
1

我正嘗試在按鈕中使用下面的代碼。我想調用DrawLineFloat。我試圖調用DrawLineFloat(),但它沒有工作。我需要輸入什麼()?vb.net中的繪圖線

感謝

Public Sub DrawLineFloat(ByVal e As PaintEventArgs) 
    ' Create pen. 
    Dim blackPen As New Pen(Color.Black, 3) 
    ' Create coordinates of points that define line. 
    Dim x1 As Single = 100.0F 
    Dim y1 As Single = 100.0F 
    Dim x2 As Single = 500.0F 
    Dim y2 As Single = 100.0F 
    ' Draw line to screen. 
    e.Graphics.DrawLine(blackPen, x1, y1, x2, y2) 
End Sub 
+0

「它沒有工作」設置,是有錯誤,或者是沒有繪製?您是否檢查過執行的功能(即必須通過它)? – 2012-03-08 14:52:59

+0

你需要傳遞()中的參數... – squelos 2012-03-08 14:54:37

回答

4

我假設你是一個形式裏面調用此,但不是在Paint事件。 所以,你需要創建用於繪製的線

Public Sub DrawLineFloat() 
     ' Create pen. 
     Dim blackPen As New Pen(Color.Black, 3) 
     ' Create coordinates of points that define line. 
     Dim x1 As Single = 100.0F 
     Dim y1 As Single = 100.0F 
     Dim x2 As Single = 500.0F 
     Dim y2 As Single = 100.0F 
     ' Draw line to screen. 

     Dim g As Graphics = Me.CreateGraphics() 
     g.DrawLine(blackPen, x1, y1, x2, y2) 

     blackPen.Dispose() 

End Sub 

圖形還要注意的是Pen對象應儘快

-1

嘗試傳遞空值(Nothning在VB)的功能。

DrawLineFloat(Nothing) 
0

爲什麼不寫這樣

Public Sub DrawLine() 
    ' Create pen. 
    Dim blackPen As New Pen(Color.Black, 3) 
    ' Create coordinates of points that define line. 
    Dim x1 As Single = 100.0F 
    Dim y1 As Single = 100.0F 
    Dim x2 As Single = 500.0F 
    Dim y2 As Single = 100.0F 
    ' Draw line to screen. 
    e.Graphics.DrawLine(blackPen, x1, y1, x2, y2) 
End Sub 

,並呼籲像

DrawLine() 
+0

它說e沒有聲明 – 2012-03-08 14:58:08