Change Color Alpha with Timer in C# - c#

I have a WinForms app which the user can choose a color from the color picker.
(I'm using the color Dialog from the Toolbox).
Now when the user chose some color I'm painting some shapes on the form using the GDI
and bitmap.
Is it possible to change this color's alpha with a timer?
because all I see is the color Dialog returns a Color or just the current values of
A,R,G,B (alpha,red,green,blue) and those values cannot be set programmatically .
I know there is Color.FromArgb() method.
I thought about this code :
Color userColor = colorsDialog.Color;
Color c = Color.FromArgb(alphaValue,userColor);
When the alphaValue is set to zero, and on each timer tick incrementing it by 1.
but it doesn't work..
Edit: the shape is drawn on the bitmap.

Related

Emission sprite with color not showing in unity

I have dots sprite which I want to become any other color. Default color is white and it's showing perfectly:
But when i try to add color, sprite is just gone:
How I could solve it?
Assuming you are using Latest Unity or Updated Shaders.
My Unity Version
Unity 2020.1.4f1
I had the same issue, the fix is simple.
In your GlowColor Node, you have set the value of your Color Alpha is set to Zero( In your default color box red you can see a small black color rectangular box that is your Alpha value which is set to zero) set the Alpha value as 255 and the black box, becomes white and then your preview should display the red dots as you require.
How to change the Alpha Value:
Click on the Default color in the GlowColor Node
A Color Picker Pop up should appear.
Above the intensity slider you will see capital A change the value to 255

c# wpf change font color with color picker

I want to change the text color of a label shown in a WPF Application within a setting menu.
so so far Just have the WPF label with the name lbText and the standard Foreground="white".
Now I added a Menu with a Xceed.Wpf.Toolkit.ColorPicker Control.
But I cant figure out how to change the color now with this Control? I always get the Error that Brush != Color, but I just want to change the Foreground value of my Label.
Foreground is actually of brush, not limited to a solid color. If you want just one plain color as foreground, construct a SolidColorBrush with the chosen color.
// suppose your color picker is named yourColorPicker
var color = yourColorPicker.SelectedColor;
if (color.HasValue) // any color selected
lbText.Foreground = new SolidColorBrush(color.Value);
else // no color selected
lbText.ClearValue(Control.ForegroundProperty);
Check out more brushes for WPF at https://learn.microsoft.com/dotnet/framework/wpf/graphics-multimedia/wpf-brushes-overview

SharpDX and setting one color as transparent (directx9)

I have a C# capture application that captures screenshot of an application and draws it to another window. Now I would like to set one color (or range) of the screenshot to be transparent and then draw it like that.
I am drawing the screenshot as sprite to 3d (directx9) surface using SharpDX.
How can I do this transparency?
When converting your screenshot to a texture, your colors should be defined by four values R,G,B,A. Alpha channel is responsible for transparency, so you should check if a color has a value / range that you want to cut out and change it's alpha value to 0.
It was a bit odd situation. My alpha modified pictures did not show up when draw:ing.
It was because I did not specify alphablend mode in .Begin-statement.
And I did not find any other way to do it than going through the whole bitmap and changing the alpha value one pixel at the time.

Get default Windows System Colors in .NET

I'm writing a custom Button control as part of a (soon to be) free Control suite, and I would like to base my (default) Control colors on the corresponding Windows System colors. So, after looking up "default windows system colors" online I could not find information on the System Colors for Windows controls (especially not Button controls).
Is there a way to get this color information (e.g. Button Border Color, Button Highlight Color, Button Hover Color, Button Clicked Background Color, etc) in .NET?
Yes. In fact, there is an entire class dedicated to this:
The SystemColors class.
...or for WPF (thanks #ORMapper), The System.Windows.SystemColors class.
There is a System Color Class out, which will provide you the Colors.
For WinForms use:
System.Drawing.SystemColors
For WPF use:
System.Windows.SystemColors
You can use also the GetSysColor function api function.
Valter
You could use the Win API, GetSysColor function...
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int GetSysColor(int nIndex);
The function returns the red, green, blue (RGB) color value of the given element.
To display the component of the RGB value, use the GetRValue, GetGValue, and GetBValue macros.
System colors for monochrome displays are usually interpreted as shades of gray.
To paint with a system color brush, an application should use GetSysColorBrush(nIndex), instead of CreateSolidBrush(GetSysColor(nIndex)), because GetSysColorBrush returns a cached brush, instead of allocating a new one.
I am wanting the same thing. My approach is to, upon initialization, create a temporary window with the background color specified in GetSysColor(COLOR_BTNFACE), the "standard" background color for dialog boxes. Then, I create a button with no text and get the colors. This temporary window is never displayed, and is destroyed immediately (WM_CREATE exit code = -1).

How to add Transparent to ColorDialog in C#

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

Categories