[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