Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
This topic has not yet been rated - Rate this topic

Color.FromRgb Method

Creates a new Color structure by using the specified sRGB color channel values.

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)
public static Color FromRgb(
	byte r,
	byte g,
	byte b
)

Parameters

r
Type: System.Byte

The sRGB red channel, R, of the new color.

g
Type: System.Byte

The sRGB green channel, G, of the new color.

b
Type: System.Byte

The sRGB blue channel, B, of the new color.

Return Value

Type: System.Windows.Media.Color
A Color structure with the specified values and an alpha channel value of 255.

The FromArgb method allows you to specify the alpha channel; the FromRgb method uses a default value of 1 for the alpha channel.

The alpha channel of a color determines the amount of transparency of the color. An alpha value of 1 indicates that the color is completely opaque, and a value of 0 indicates that the color is completely transparent.

The sRGB channels (A, R, G, B) and the ScRGB channels (ScA, ScR, ScG, ScB) of the Color structure are synchronized properties. For example, when R, the sRGB red channel, is modified the ScRGB red channel, ScR, is transformed to the equivalent value.

The following example shows how to use the FromRgb method to create a Color structure.

private Color FromRgbExample()
{
    // Create a green color using the FromRgb static method.
    Color myRgbColor = new Color();
    myRgbColor = Color.FromRgb(0, 255, 0);
    return myRgbColor;
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.