I have an access color (light yellow, or 153,255,255) but when I try to use this RGB combo in my Windows Form by using such syntax
System.Drawing.Color ly = System.Drawing.Color.FromArgb(153, 255, 255);
this.BackColor = ly;
the windows form does not produce the same color as my Access Form color does. I also tried to use this
this.BackColor = Color.FromName("LightYellow");
to no such success. Did I translate the color incorrectly? Or can I not use the same colors?
EDIT -
#Alex K thank you for your response, I used this website to attempt to convert and that is the RGB color that it gave. Take a look here:
http://www.numberconverter.net/get-computer-data/color-code-converter/from-rgb-to-ms-access-color/
Access colors seems to be represented as BGR, not RGB (You can verify that quickly by inputting the values in MSPaint). You must switch the values of the first and last values.
So you will need to use
System.Drawing.Color ly = System.Drawing.Color.FromArgb(255, 255, 153);
to obtain your light yellow color.
If instead you want to use the literal name, you can use FromKnownColor which will give you an enum of all color names. It's much more error-proof.
this.BackColor = Color.FromKnownColor(KnownColor.LightYellow);
This won't restrict you on the color choice either, according to the doc FromName takes as an input
Valid names are the same as the names of the elements of the
KnownColor enumeration.
Related
The control I want to change to his color is a ToolStripItem.
When i use this
item.BackColor = Color.Black;
item.ForeColor = Color.Transparent;
It works as expected
But when i try this
item.BackColor = Color.Black;
item.ForeColor = Color.FromArgb(0, 255, 255, 255);
or this
item.BackColor = Color.White;
item.ForeColor = Color.FromArgb(0, 0, 0, 0);
the alpha component is like completely ignored
Any idea where the problem might have come from?
Edit : Now i know there the problem is, but i'm still unable to use transparency for text.
Some aditional informations : The item i need to change his text color is an ToolStripMenuItem. All the items needs to have a different color, so i can't just use a Renderer for my MenuStrip.
Thanks a lot !
ToolStripRenderer uses TextRenderer.DrawText which uses WindowsGraphics.DrawText` which uses GDI functions to draw text.
For Color.Transparent it doesn't render anything. For other colors GDI functions ignore the alpha part of ARGB color.
What happens behind the scene?
In the internal implementations in WindowsGraphics.DrawText, you can see there is a specific criteria for not drawing the text if the color is Color.Transparent.
So for Color.Transparent it doesn't draw the text:
if (string.IsNullOrEmpty(text) || foreColor == Color.Transparent)
{
return;
}
About Color.FromArgb(0,x,y,z), since Color.Transparent and Color.FromArgb(0,x,y,z) are not the same, so it tries to draw text when you pass Color.FromArgb(0,x,y,z). It uses a COLORREF structure to pass to SetTextColor. you will see it always ignores the A value:
When specifying an explicit RGB color, the COLORREF value has the following hexadecimal form:
0x00bbggrr
The low-order byte contains a value for the relative intensity of red;
the second byte contains a value for green; and the third byte
contains a value for blue. The high-order byte must be zero.
How to draw transparent/semi-transparent text?
If you need transparency support for drawing strings, you can override OnRenderItemText method of the ToolStripRenderer and use Graphics.DrawString instead.
How is color addition done in android? For my pathtracer i am storing a Color but i didn't find a way to get the r,g,b values back.
I think if i want to get red i do this:
returnColor.red(0)
but it doesn't work.
Since i work more with android in the last week i do more and more think why stuff is made so complicated in android? In C# you just add the r,g,b values and you don't get an integer back if you type
Color.White
you can use the static method red of the Color class:
int red = Color.red(color)
The same class has the argb method that allows you to get the int representing your color, through the 4 components. E.g.
int color = Color.argb(255, 255, 255, 255);
Here you can find the documentation
I want to add Transparent Color to my ColorDialog.
I tried this code :
MyDialog.CustomColors = new int[] { Color.Transparent.ToArgb() };
MyDialog.ShowDialog();
string hex = ColorTranslator.ToHtml(MyDialog.Color);
MessageBox.Show(hex);
But, when I pick my Custom Color (I mean Transparent), the messageBox show me "White" instead of "Transparent". convert to White itself. But I want to pick Transparent. How can I do that?
My guess is that it is showing the colour behind. Please post your control XAML to be sure.
A common workaround to that is to put a chequerboard pattern behind your swatch control, so that as the alpha is decreased, the chequer shows through. Otherwise, how else do you show something that has no visibility?
The CustomColors property accepts colors in an Int32 composed of the BGR (blue, green, red) and you are passing it an ARGB representation of Transparent color. The A in ARGB controls the alpha channel and transparency. I would put a check box on the form for user to specify color transparency . Else you may map your white in the color dialog box to transparent selection.
If (dlgCol.Color.ToArgb() == Color.White.ToArgb() )
{
btnColor.BackColor = Color.Transparent;
}
http://en.wikipedia.org/wiki/RGBA_color_space
let's say that I have a HEX color #a08040. How can I determine in C#, if that color is the one of the many hues of the Brown color ?
In the other words, I have 4 colors: Brown, Red, Black, Gray.
How to determine what color hue is my HEX color?
If you are using WinForms, the Color.GetHue method will do exactly what you want.
Edit
Unfortunately, there is no WPF equivalent to GetHue, you'll have to convert to a WinForms Color if you want to use GetHue from WPF. You could also compute the Hue yourself, if you're feeling frisky... Wikipedia has the formula you'd need to use.
I have created an iframe which contains the label, "powered by MyWebsite.site"
The "iframe itself" accepts arguments, so other webmasters may customize the appearance of it.
The problem is that since the background of the iframe could be customized, anyone can "vanish" the "powered by MyWebsite.site".
So what option do i have? How should i dynamically change the label color depending on any background?
Assuming you have access to the background color (in hex; e.g. #ff0000) defined by the webmaster, you should be able to invert the color using an algorithm such as the one that follows. The given algorithm converts the hex color value to RGB. Then it subtracts each component of the RGB value from 255, which yields the inverse. The inverted RGB value is then converted back into a hex color value. Apply the inverted hex color value to the "powered by..." text and you should be all set.
http://www.codingforums.com/archive/index.php/t-47335.html
Note that this calculation can be done directly in hex, but that may be a little more difficult to comprehend (depending on how your mind "thinks" about these things).