一个简单vb程序的设计

来源:百度知道 编辑:UC知道 时间:2024/05/11 04:00:46
我是初学者 在书上看了个 绘图的程序如下
Option Explicit
Dim paintnow As Boolean

Private Sub Form_Load()

DrawWidth = 5
ForeColor = RGB(0, 0, 0)

End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
paintnow = True
End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If paintnow Then
PSet (X, Y)
End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
paintnow = False
End Sub

运行之后只是一种颜色 ,如何才能自己设置颜色来绘画?

添加一个按钮控件,用来激活颜色选择对话框
添加一个通用对话框控件,用来显示颜色选择对话框
单击按钮后,选择颜色确定就可以了
注意,添加通用对话框控件前要在部件中添加Microsoft common dialog6.0
修改后完全代码如下
Option Explicit
Dim paintnow As Boolean

Private Sub Command1_Click()
CommonDialog1.ShowColor
ForeColor = CommonDialog1.Color
End Sub

Private Sub Form_Load()

DrawWidth = 5
ForeColor = RGB(0, 0, 0)

End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
paintnow = True
End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If paintnow Then
PSet (X, Y)
End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
paintnow = False
End Sub

太奢侈了