The Color Changer Application


 
  1. Start a new project and, in the New Project dialog box, select Visual J# 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 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.set_BackColor(System.Drawing.Color.FromArgb(127, 127, 127));
    }
  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 ValueRed, ValueGreen, ValueBlue;
    
    	ValueRed = 255 - scrRed.get_Value();
    	ValueGreen = 255 - scrGreen.get_Value();
    	ValueBlue  = 255 - scrBlue.get_Value();
    	pnlPreview.set_BackColor(System.Drawing.Color.FromArgb(ValueRed, ValueGreen, ValueBlue));
    }
    
    private void scrGreen_Scroll (Object sender, System.Windows.Forms.ScrollEventArgs e)
    {	
    	int ValueRed, ValueGreen, ValueBlue;
    
    	ValueRed = 255 - scrRed.get_Value();
    	ValueGreen = 255 - scrGreen.get_Value();
    	ValueBlue  = 255 - scrBlue.get_Value();
    	pnlPreview.set_BackColor(System.Drawing.Color.FromArgb(ValueRed, ValueGreen, ValueBlue));
    }
    
    private void scrBlue_Scroll (Object sender, System.Windows.Forms.ScrollEventArgs e)
    {
    	int ValueRed, ValueGreen, ValueBlue;
    
    	ValueRed = 255 - scrRed.get_Value();
    	ValueGreen = 255 - scrGreen.get_Value();
    	ValueBlue  = 255 - scrBlue.get_Value();
    	pnlPreview.set_BackColor(System.Drawing.Color.FromArgb(ValueRed, ValueGreen, ValueBlue));
    }
  16. Press F5 to test the application.

Home Copyright 2004 FunctionX, Inc.