Actualización: noviembre 2007
Representa un color de ARGB (alfa, rojo, verde, azul).
Espacio de nombres:
System.Drawing
Ensamblado:
System.Drawing (en System.Drawing.dll)
Visual Basic (Declaración)
<SerializableAttribute> _
<TypeConverterAttribute(GetType(ColorConverter))> _
Public Structure Color
[SerializableAttribute]
[TypeConverterAttribute(typeof(ColorConverter))]
public struct Color
[SerializableAttribute]
[TypeConverterAttribute(typeof(ColorConverter))]
public value class Color
/** @attribute SerializableAttribute */
/** @attribute TypeConverterAttribute(ColorConverter) */
public final class Color extends ValueType
JScript admite el uso de estructuras, pero no admite la declaración de estructuras nuevas.
Los colores con nombre se representan utilizando las propiedades de la estructura Color. Para obtener más información sobre estos colores, vea Colors by Name en MSDN Library. Para determinar el componente alfa, rojo, verde o azul de un color, utilice la propiedad A, R, G o B, respectivamente.
Puede crear un color personalizado utilizando uno de los métodos FromArgb.
En el ejemplo de código siguiente se muestran las propiedades G, B, R y A de una estructura Color y el miembro de Implicit.
Este ejemplo se ha diseñado para un formulario Windows Forms. Pegue este código en el formulario y llame al método ShowPropertiesOfSlateBlue desde el método controlador del evento Paint del formulario, pasando e como parámetro de PaintEventArgs.
Private Sub ShowPropertiesOfSlateBlue(ByVal e As PaintEventArgs)
Dim slateBlue As Color = Color.FromName("SlateBlue")
Dim g As Byte = slateBlue.G
Dim b As Byte = slateBlue.B
Dim r As Byte = slateBlue.R
Dim a As Byte = slateBlue.A
Dim text As String = _
String.Format("Slate Blue has these ARGB values: Alpha:{0}, " _
& "red:{1}, green: {2}, blue {3}", New Object() {a, r, g, b})
e.Graphics.DrawString(text, New Font(Me.Font, FontStyle.Italic), _
New SolidBrush(slateBlue), _
New RectangleF(New PointF(0.0F, 0.0F), _
Size.op_Implicit(Me.Size)))
End Sub
private void ShowPropertiesOfSlateBlue(PaintEventArgs e)
{
Color slateBlue = Color.FromName("SlateBlue");
byte g = slateBlue.G;
byte b = slateBlue.B;
byte r = slateBlue.R;
byte a = slateBlue.A;
string text = String.Format("Slate Blue has these ARGB values: Alpha:{0}, " +
"red:{1}, green: {2}, blue {3}", new object[]{a, r, g, b});
e.Graphics.DrawString(text,
new Font(this.Font, FontStyle.Italic),
new SolidBrush(slateBlue),
new RectangleF(new PointF(0.0F, 0.0F), this.Size));
}
void ShowPropertiesOfSlateBlue( PaintEventArgs^ e )
{
Color slateBlue = Color::FromName( "SlateBlue" );
Byte g = slateBlue.G;
Byte b = slateBlue.B;
Byte r = slateBlue.R;
Byte a = slateBlue.A;
array<Object^>^temp0 = {a,r,g,b};
String^ text = String::Format( "Slate Blue has these ARGB values: Alpha:{0}, "
"red:{1}, green: {2}, blue {3}", temp0 );
e->Graphics->DrawString( text, gcnew System::Drawing::Font( this->Font,FontStyle::Italic ), gcnew SolidBrush( slateBlue ), RectangleF(PointF(0.0F,0.0F),this->Size) );
}
private void ShowPropertiesOfSlateBlue(PaintEventArgs e)
{
Color slateBlue = Color.FromName("SlateBlue");
ubyte g = slateBlue.get_G();
ubyte b = slateBlue.get_B();
ubyte r = slateBlue.get_R();
ubyte a = slateBlue.get_A();
String text = String.Format(
"Slate Blue has these ARGB values: Alpha:{0}, "
+ "red:{1}, green: {2}, blue {3}",
new Object[] { (UInt16)a, (UInt16)r, (UInt16)g, (UInt16)b });
e.get_Graphics().DrawString(text,
new Font(this.get_Font(), FontStyle.Italic),
new SolidBrush(slateBlue),
new RectangleF(new PointF(0, 0),
Size.op_Implicit(this.get_Size())));
} //ShowPropertiesOfSlateBlue
Seguridad para subprocesos
Todos los miembros static (Shared en Visual Basic) públicos de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile para Smartphone, Windows Mobile para Pocket PC, Xbox 360
.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.
.NET Framework
Compatible con: 3.5, 3.0, 2.0, 1.1, 1.0
.NET Compact Framework
Compatible con: 3.5, 2.0, 1.0
XNA Framework
Compatible con: 1.0
Referencia
Otros recursos