|
- Start a new project and, in the New Project dialog box, select
Visual C# Projects from the Projects Types list
- On the Templates list, click Windows Application
- Set the Name to ColorChanger
- In the Location box, specify the path. Otherwise, type C:\Programs\MSVCS
.Net and click OK
Here is the form we need to design:
- 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
- From the Toolbox, add three VScrollBar controls and Name them scrRed,
scrGreen, and scrBlue
- Set the Minimum to 0 and the Maximum to 255 for each scroll bar
- Set each Value to 128
- Add a Button control. Name it btnClose and its Text value to
&Close
- Design the rest of the form as you like
- 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);
}
|
- Double-click the Close button and implement its OnClick event as
follows:
private void btnClose_Click(object sender, System.EventArgs e)
{
Close();
}
|
- Double-click the left ScrollBar control on the form to access its
OnScroll event
- In the same way, double-click the middle and the right scroll bars.
- 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);
}
|
- Press F5 to test the application.
|
|