[vb]
Public Class Form
Dim DrawState As Boolean
Dim PreX As Single
Dim PreY As Single
Dim eP As New Pen(ColorBlack ) 構造黑色畫筆並將它賦給對象變量eP
Dim g As Graphics = MeCreateGraphics 在窗體上構造一塊畫布並將它賦給對象變量g
Private Sub Form_Load(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles MyBaseLoad
將DrawState初始化為False表示提筆
DrawState = False
End Sub
Private Sub Form_MouseDown(ByVal sender As Object ByVal e As SystemWindowsFormsMouseEventArgs) Handles MeMouseDown
當鼠標左鍵被按下時把DrawState設為True表示落筆開始畫線
Dim g As Graphics = MeCreateGraphics
If eButton = WindowsFormsMouseButtonsLeft Then
DrawState = True 設置畫圖狀態
PreX = eX PreX和PreY保存了線條的起點
PreY = eY
End If
當按住鼠標右鍵時畫一個直徑為的圓
If eButton = WindowsFormsMouseButtonsRight Then
gDrawEllipse(eP eX eY )
End If
End Sub
Private Sub Form_MouseMove(ByVal sender As Object ByVal e As SystemWindowsFormsMouseEventArgs) Handles MeMouseMove
當鼠標移動時如果處於畫線狀態則在(PreXPreY)與(XY)之間畫一條直線
Dim g As Graphics = MeCreateGraphics
If DrawState = True Then
gDrawLine(eP PreX PreY eX eY)
PreX = eX
PreY = eY
End If
End Sub
Private Sub Form_MouseUp(ByVal sender As Object ByVal e As SystemWindowsFormsMouseEventArgs) Handles MeMouseUp
當釋放鼠標左鍵時解除畫線狀態
If eButton = WindowsFormsMouseButtonsLeft Then
DrawState = False
End If
End Sub
End Class
Public Class Form
Dim DrawState As Boolean
Dim PreX As Single
Dim PreY As Single
Dim eP As New Pen(ColorBlack ) 構造黑色畫筆並將它賦給對象變量eP
Dim g As Graphics = MeCreateGraphics 在窗體上構造一塊畫布並將它賦給對象變量g
Private Sub Form_Load(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles MyBaseLoad
將DrawState初始化為False表示提筆
DrawState = False
End Sub
Private Sub Form_MouseDown(ByVal sender As Object ByVal e As SystemWindowsFormsMouseEventArgs) Handles MeMouseDown
當鼠標左鍵被按下時把DrawState設為True表示落筆開始畫線
Dim g As Graphics = MeCreateGraphics
If eButton = WindowsFormsMouseButtonsLeft Then
DrawState = True 設置畫圖狀態
PreX = eX PreX和PreY保存了線條的起點
PreY = eY
End If
當按住鼠標右鍵時畫一個直徑為的圓
If eButton = WindowsFormsMouseButtonsRight Then
gDrawEllipse(eP eX eY )
End If
End Sub
Private Sub Form_MouseMove(ByVal sender As Object ByVal e As SystemWindowsFormsMouseEventArgs) Handles MeMouseMove
當鼠標移動時如果處於畫線狀態則在(PreXPreY)與(XY)之間畫一條直線
Dim g As Graphics = MeCreateGraphics
If DrawState = True Then
gDrawLine(eP PreX PreY eX eY)
PreX = eX
PreY = eY
End If
End Sub
Private Sub Form_MouseUp(ByVal sender As Object ByVal e As SystemWindowsFormsMouseEventArgs) Handles MeMouseUp
當釋放鼠標左鍵時解除畫線狀態
If eButton = WindowsFormsMouseButtonsLeft Then
DrawState = False
End If
End Sub
End Class
改法
[vb]
Public Class Form
Dim DrawState As Boolean
Dim PreX As Single
Dim PreY As Single
Dim eP As New Pen(ColorBlack ) 構造黑色畫筆並將它賦給對象變量eP
Dim g As Graphics 在窗體上構造一塊畫布並將它賦給對象變量g
Private Sub Form_Load(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles MyBaseLoad
將DrawState初始化為False表示提筆
DrawState = False
End Sub
Private Sub Form_MouseDown(ByVal sender As Object ByVal e As SystemWindowsFormsMouseEventArgs) Handles MeMouseDown
當鼠標左鍵被按下時把DrawState設為True表示落筆開始畫線
Dim g As Graphics = MeCreateGraphics
If eButton = WindowsFormsMouseButtonsLeft Then
DrawState = True 設置畫圖狀態
PreX = eX PreX和PreY保存了線條的起點
PreY = eY
End If
當按住鼠標右鍵時畫一個直徑為的圓
If eButton = WindowsFormsMouseButtonsRight Then
gDrawEllipse(eP eX eY )
End If
End Sub
Private Sub Form_MouseMove(ByVal sender As Object ByVal e As SystemWindowsFormsMouseEventArgs) Handles MeMouseMove
當鼠標移動時如果處於畫線狀態則在(PreXPreY)與(XY)之間畫一條直線
Dim g As Graphics = MeCreateGraphics
If DrawState = True Then
gDrawLine(eP PreX PreY eX eY)
PreX = eX
PreY = eY
End If
End Sub
Private Sub Form_MouseUp(ByVal sender As Object ByVal e As SystemWindowsFormsMouseEventArgs) Handles MeMouseUp
當釋放鼠標左鍵時解除畫線狀態
If eButton = WindowsFormsMouseButtonsLeft Then
DrawState = False
End If
End Sub
Private Sub Form_Resize(ByVal sender As Object ByVal e As SystemEventArgs) Handles MeResize
g = MeCreateGraphics
End Sub
End Class
Public Class Form
Dim DrawState As Boolean
Dim PreX As Single
Dim PreY As Single
Dim eP As New Pen(ColorBlack ) 構造黑色畫筆並將它賦給對象變量eP
Dim g As Graphics 在窗體上構造一塊畫布並將它賦給對象變量g
Private Sub Form_Load(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles MyBaseLoad
將DrawState初始化為False表示提筆
DrawState = False
End Sub
Private Sub Form_MouseDown(ByVal sender As Object ByVal e As SystemWindowsFormsMouseEventArgs) Handles MeMouseDown
當鼠標左鍵被按下時把DrawState設為True表示落筆開始畫線
Dim g As Graphics = MeCreateGraphics
If eButton = WindowsFormsMouseButtonsLeft Then
DrawState = True 設置畫圖狀態
PreX = eX PreX和PreY保存了線條的起點
PreY = eY
End If
當按住鼠標右鍵時畫一個直徑為的圓
If eButton = WindowsFormsMouseButtonsRight Then
gDrawEllipse(eP eX eY )
End If
End Sub
Private Sub Form_MouseMove(ByVal sender As Object ByVal e As SystemWindowsFormsMouseEventArgs) Handles MeMouseMove
當鼠標移動時如果處於畫線狀態則在(PreXPreY)與(XY)之間畫一條直線
Dim g As Graphics = MeCreateGraphics
If DrawState = True Then
gDrawLine(eP PreX PreY eX eY)
PreX = eX
PreY = eY
End If
End Sub
Private Sub Form_MouseUp(ByVal sender As Object ByVal e As SystemWindowsFormsMouseEventArgs) Handles MeMouseUp
當釋放鼠標左鍵時解除畫線狀態
If eButton = WindowsFormsMouseButtonsLeft Then
DrawState = False
End If
End Sub
Private Sub Form_Resize(ByVal sender As Object ByVal e As SystemEventArgs) Handles MeResize
g = MeCreateGraphics
End Sub
End Class
From:http://tw.wingwit.com/Article/program/net/201311/13744.html