Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a new color?

Tags:

I have a form in C# that I want to enter as red, green and blue in 3 TextBox controls and make a new color. For example: red=3, green=2, blue=5 when I click on "MAKE COLOR" button, a label shows me the new color.

like image 539
sara Avatar asked Dec 02 '12 14:12

sara


People also ask

Is it possible to create a new color?

Today researchers use physics to invent new colours, inspired perhaps by the iridescent shades created by structures in butterfly wings that scatter light. These new structural colours are the result of an interaction between light and nanoscale features many times thinner than human hair.


1 Answers

Let us assume that you have some code that looks similar to this:

int red = Convert.ToInt32(RedColorComponentValueTextBox.Text); int green = Convert.ToInt32(GreenColorComponentValueTextBox.Text); int blue = Convert.ToInt32(BlueColorComponentValueTextBox.Text); //Don't forget to try/catch this 

Then to create the color from these values, try

Color c = Color.FromArgb(red, green, blue); 

Then set the ForeColor property (or the BackColor property -- not sure which one you meant to change) of the label to c.

You will need to have

using System.Drawing; 

in your code file (or class) preamble.

Note: If you wanted to also have an alpha component, you could try this:

Color c = Color.FromArgb(alpha, red, green, blue); 

General hint: If you want to use an HTML/CSS color specification of the form #RRGGBB e.g. #335577, try this pattern

int red = 0x33, green = 0x55, blue = 0x77;  
like image 90
Miltos Kokkonidis Avatar answered Sep 20 '22 20:09

Miltos Kokkonidis