The Color Changer Application


 
  1. Start a new project and, in the New Project dialog box, select Visual C# 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\MSVCS .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 void Form1_Load(object sender, System.EventArgs e)
    {
    	pnlPreview.BackColor = System.Drawing.Color.FromArgb(128, 128, 128);
    }
  12. Double-click the Close button and implement its OnClick event as follows:
     
    private void btnClose_Click(object sender, System.EventArgs e)
    {
    	Close();
    }
  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 void scrRed_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
    {
    	int RedValue, GreenValue, BlueValue;
    
    	RedValue = scrRed.Value;
    	GreenValue = scrGreen.Value;
    	BlueValue = scrBlue.Value;
    			
    	pnlPreview.BackColor = System.Drawing.Color.FromArgb(RedValue, GreenValue, BlueValue);
    }
    
    private void scrGreen_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
    {
    	int RedValue, GreenValue, BlueValue;
    
    	RedValue = scrRed.Value;
    	GreenValue = scrGreen.Value;
    	BlueValue = scrBlue.Value;
    			
    	pnlPreview.BackColor = System.Drawing.Color.FromArgb(RedValue, GreenValue, BlueValue);
    }
    
    private void scrBlue_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
    {
    	int RedValue, GreenValue, BlueValue;
    
    	RedValue = scrRed.Value;
    	GreenValue = scrGreen.Value;
    	BlueValue = scrBlue.Value;
    			
    	pnlPreview.BackColor = System.Drawing.Color.FromArgb(RedValue, GreenValue, BlueValue);
    }
  16. Press F5 to test the application.
 

Home Copyright © 2002 Functionx, Inc.