How to Display Rainbow Color in C#

Description :



Here is a simple combination of Graphic class to display rainbow color in C#.
First we will use a User Control in Windows Form in C#

Follow these Steps:

1.Open Visual Studio.
2.New -> Project -> Windows Application and name it as Rainbow.
3.In Solution Explorer Right Click on Project Rainbow and Click on Add->New Item->UserControl.
4.Name the UserControl as userainbow.cs.
5.In userainbow.cs add a Paint Event.
6.In userainbow.cs's Paint Event copy this code as it is.

//In Userainbow.cs Paint Event
int red = 0, green = 0, blue = 0;
int cnt = 0;
int cl = 255 / (this.Width / 5);
//blue-aqua

blue = 255;
for (green = 0; green < 256; green += cl, cnt++)
{
e.Graphics.DrawLine(new Pen(Color.FromArgb(red, green, blue)), cnt, 0, cnt, this.Height);
}
//aqua-green
green = 255;
for (blue = 255; blue > 0; blue -= cl, cnt++)
{
e.Graphics.DrawLine(new Pen(Color.FromArgb(red, green, blue)), cnt, 0, cnt, this.Height);
}
//green-red
blue = 0;
for (red = 0; red < 256; red += cl, cnt++)
{
e.Graphics.DrawLine(new Pen(Color.FromArgb(red, green, blue)), cnt, 0, cnt, this.Height);
}
//red-yellow
red = 255;
for (green = 255; green > 0; green -= cl, cnt++)
{
e.Graphics.DrawLine(new Pen(Color.FromArgb(red, green, blue)), cnt, 0, cnt, this.Height);
}


7.Press Build or Press F6 to build usercontrol.
8.Now we have to add this UserControl.cs ie. userainbow.cs in Windows Form.
9.In our main Windows Form drag the usercontrol.cs i.e userainbow.cs from toolbox.
10.When you will add the usercontrol to windows main form a raindow color will be Seen.
11.Lastly build your project and debug it.
12.**NOTE:you can resize the usercontrol before adding to windows form.

IF ANY PROBLEM OCCURS PLZ CONTACT 9867270756 or softwarenik@yahoo.in


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: