This code implements a paint application that allows the user to select a line color, style, and width using dropdown menus. When the user clicks and drags the mouse, a line is drawn on the form in the selected color and style, with thickness determined by the selected width. Clicking a button clears the form.
2. Code:
Private Sub Form_Load()
Combo1.Text = "Select"
Combo2.Text = "Select"
Combo3.Text = "Select"
Combo1.AddItem "Red"
Combo1.AddItem "Green"
Combo1.AddItem "Blue"
Combo1.AddItem "Cyan"
Combo2.AddItem "Solid"
Combo2.AddItem "Dash"
Combo2.AddItem "Dot"
Combo2.AddItem "Dash-Dot"
Combo2.AddItem "Dash-Dot-Dot"
Combo2.AddItem "Transparent"
Combo2.AddItem "Inside-Solid"
For i = 1 To 10
Combo3.AddItem (i)
Next
End Sub
3. Private Sub Command1_Click()
Form1.Cls
End Sub
Private Sub Combo2_Click()
If Combo2.Text = "Solid" Then
Form1.DrawStyle = vbSolid
ElseIf Combo2.Text = "Dash" Then
Form1.DrawStyle = vbDash
ElseIf Combo2.Text = "Dot" Then
Form1.DrawStyle = vbDot
ElseIf Combo2.Text = "Dash-Dot" Then
Form1.DrawStyle = vbDashDot
ElseIf Combo2.Text = "Dash-Dot-Dot" Then
Form1.DrawStyle = vbDashDotDot
ElseIf Combo2.Text = "Transparent" Then
Form1.DrawStyle = vbTransparent
ElseIf Combo2.Text = "Inside Solid" Then
Form1.DrawStyle = vbInsideSolid
End If
End Sub
4. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y
As Single)
Form1.DrawWidth = Combo3.Text
If Button = 1 Then
If Combo1.Text = "Red" Then
Form1.PSet (X, Y), vbRed
ElseIf Combo1.Text = "Green" Then
Form1.PSet (X, Y), vbGreen
ElseIf Combo1.Text = "Blue" Then
Form1.PSet (X, Y), vbBlue
ElseIf Combo1.Text = "Cyan" Then
Form1.PSet (X, Y), vbCyan
End If
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y
As Single)
If Shift = 0 And Button = 1 Then
If Combo1.Text = "Red" Then
Form1.Line -(X, Y), vbRed
ElseIf Combo1.Text = "Green" Then
5. Form1.Line -(X, Y), vbGreen
ElseIf Combo1.Text = "Blue" Then
Form1.Line -(X, Y), vbBlue
ElseIf Combo1.Text = "Cyan" Then
Form1.Line -(X, Y), vbCyan
End If
End If
End Sub