1. Start Visual Basic and create a standard project Color Picker. Rename Form1 form to Color Picker under Color Picker project.
2. Change the form’s name from Form1 to frmColor and its Text property to “Color Picker”.
3. From the toolbox, select the PictureBox and create a box within the form. Modify its name to “picRed” and select red from the pallete of the BackColor property.
4. Build three more Picture boxes as shown. Change its Name and BackColor property as follows:
picGreen Green
picYellow Yellow
picBlue Blue
5. Create a label control and change its Name property to lblColor. Modify its Autosize property to True. Type “Please point your cursor to a box.” on the Text property and select the desired font in the Font Property.
6. Double click the frmColor to display the Code window Color Picker.vb and enter the following:
Public Class frmColor
Private Sub frmColor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles MyBase.Load
End Sub
Private Sub frmColor_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
lblColor.ForeColor = Color.Chocolate
lblColor.Text = "Please point your cursor to a box."
End Sub
Private Sub picBlue_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles picBlue.Click
lblColor.ForeColor = Color.Blue
End Sub
Private Sub picBlue_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picBlue.MouseMove
lblColor.Text = "Click this box to change my color to Blue"
End Sub
Private Sub picRed_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles picRed.Click
lblColor.ForeColor = Color.Red
End Sub
Private Sub picRed_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picRed.MouseMove
lblColor.Text = "Click this box to change my color to Red"
End Sub
Private Sub picGreen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles picGreen.Click
lblColor.ForeColor = Color.Green
End Sub
Private Sub picGreen_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picGreen.MouseMove
lblColor.Text = "Click this box to change my color to Green"
End Sub
Private Sub picYellow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles picYellow.Click
lblColor.ForeColor = Color.Yellow
End Sub
Private Sub picYellow_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picYellow.MouseMove
lblColor.Text = "Click this box to change my color to Yellow"
End Sub
End Class
7. Save your work as Color Picker and run.
No comments:
Post a Comment