Color Changer

 

This exercise combines a panel, a button, and three scroll bars combined to create an application.

Prerequisites:
Panel
Button
TrackBar

Color Changer

 

Practical LearningPractical Learning: Creating the Application

 
  1. Start a new Windows Forms Application project and name it ColorChanger1
  2. Design the form as follows:
     
    Color Changer
    Control Name Text Other Properties
    Panel pnlPreview   BackColor: Blue
    BorderStyle: Fixed3d
    TrackBar trbRed Maximum: 255
    TickFrequency: 15
    TrackBar trbGreen   Maximum: 255
    TickFrequency: 15
    TrackBar trbBlue   Maximum: 255
    TickFrequency: 15
    Value: 255
    Label   R  
    Label   G  
    Label B
    Button btnClose Close  
  3. Double-click the left track bar and implement its event as follows:
     
    System::Void trbRed_Scroll(System::Object^  sender, System::EventArgs^  e)
    {
    	 int RedValue   = trbRed->Value;
    	int GreenValue = trbGreen->Value;
    	int BlueValue  = trbBlue->Value;
    
    	pnlPreview->BackColor = 
    		System::Drawing::Color::FromArgb(RedValue,
    						 GreenValue,
    						 BlueValue);
    }
  4. Return to the form
  5. Double-click the middle track bar and implement its event as follows:
     
    System::Void trbGreen_Scroll(System::Object^ sender, System::EventArgs^ e)
    {
    	int RedValue = trbRed->Value;
    	int GreenValue = trbGreen->Value;
    	int BlueValue  = trbBlue->Value;
    
    	pnlPreview->BackColor = 
    		System::Drawing::Color::FromArgb(RedValue,
    						 GreenValue,
    						 BlueValue);
    }
  6. Return to the form
  7. Double-click the right track bar and implement its event as follows:
     
    System::Void trbBlue_Scroll(System::Object^ sender, System::EventArgs^ e)
    {
    	 int RedValue = trbRed->Value;
    	int GreenValue = trbGreen->Value;
    	int BlueValue  = trbBlue->Value;
    
    	pnlPreview->BackColor = 
    		System::Drawing::Color::FromArgb(RedValue,
    						 GreenValue,
    						 BlueValue);
    }
  8. Return to the form
  9. Double-click the Close button to access its Click() event and implement it as follows:
     
    System::Void btnClose_Click(System::Object^ sender, System::EventArgs^ e)
    {
    	 Close();
    }
  10. Test the application
  11. Close the form
 
 

Home Copyright © 2002-2007 FunctionX, Inc.