The Color Changer Application


 
  1. Start a new project and, in the New Project dialog box, select Visual Basic Projects from the Projects Types list
  2. On the Templates list, click Windows Application
  3. Set the Name to ColorChanger
  4. In the Location box, specify the path. Otherwise, type C:\Programs\MSVB .Net and click OK
    Here is the form we need to design:
     
  5. From the Toolbox, click Panel and click on the form. On the Properties window, change its Name to pnlPreview and set its BorderStyle to Fixed3D
  6. From the Toolbox, add three VScrollBar controls and Name them scrRed, scrGreen, and scrBlue
  7. Set the Minimum to 0 and the Maximum to 255 for each scroll bar
  8. Set each Value to 128
  9. Add a Button control. Name it btnClose and its Text value to &Close
  10. Design the rest of the form as you like
  11. Double-click an unoccupied area on the form and implement its OnLoad event as follows:
     
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            pnlPreview.BackColor = System.Drawing.Color.FromArgb(128, 128, 128)
    End Sub
  12. Double-click the Close button and implement its OnClick event as follows:
     
    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
            Close()
    End Sub
  13. Double-click the left ScrollBar control on the form to access its OnScroll event
  14. In the same way, double-click the middle and the right scroll bars.
  15. Implement their events as follows:
     
    Private Sub scrRed_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles scrRed.Scroll
      	Dim RedValue As Integer
      	Dim GreenValue As Integer
      	Dim BlueValue As Integer
    
      	RedValue = scrRed.Value
      	GreenValue = scrGreen.Value
      	BlueValue = scrBlue.Value
    
      	pnlPreview.BackColor = System.Drawing.Color.FromArgb(RedValue, GreenValue, BlueValue)
    End Sub
    
    Private Sub scrGreen_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles scrGreen.Scroll
      	Dim RedValue As Integer
      	Dim GreenValue As Integer
      	Dim BlueValue As Integer
    
      	RedValue = scrRed.Value
      	GreenValue = scrGreen.Value
      	BlueValue = scrBlue.Value
    
      	pnlPreview.BackColor = System.Drawing.Color.FromArgb(RedValue, GreenValue, BlueValue)
    End Sub
    
    Private Sub scrBlue_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles scrBlue.Scroll
      	Dim RedValue As Integer
      	Dim GreenValue As Integer
      	Dim BlueValue As Integer
    
      	RedValue = scrRed.Value
      	GreenValue = scrGreen.Value
    	BlueValue = scrBlue.Value
    
    	pnlPreview.BackColor = System.Drawing.Color.FromArgb(RedValue, GreenValue, BlueValue)
    End Sub
  16. Press F5 to test the application
 

Home Copyright © 2002 FunctionX, Inc.