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.
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With