vb.net

位置:IT落伍者 >> vb.net >> 浏览文章

vb.net graphic 简单的画图程序


发布日期:2023年12月20日
 
vb.net graphic 简单的画图程序

[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

               

上一篇:VB.NET编写测试硬盘速度的程序

下一篇:VB.NET关于加密算法