This exercise combines a panel, a button, and three
scroll bars combined to create an application.
Prerequisites:
Panel
Button
TrackBar
Practical
Learning: Creating the Application |
|
- Start a new Windows Forms Application project and name it ColorChanger1
- Design the form as follows:
|
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 |
|
|
- 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);
}
|
- Return to the form
- 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);
}
|
- Return to the form
- 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);
}
|
- Return to the form
- 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();
}
|
- Test the application
- Close the form
|
|