Color.FromName(String) Método

Definición

Crea una estructura Color a partir del nombre especificado de un color predefinido.Creates a Color structure from the specified name of a predefined color.

public:
 static System::Drawing::Color FromName(System::String ^ name);
public static System.Drawing.Color FromName (string name);
static member FromName : string -> System.Drawing.Color
Public Shared Function FromName (name As String) As Color

Parámetros

name
String

Cadena que es el nombre de un color predefinido.A string that is the name of a predefined color. Los nombres válidos son los nombres de los elementos de la enumeración KnownColor.Valid names are the same as the names of the elements of the KnownColor enumeration.

Devoluciones

La Color que este método crea.The Color that this method creates.

Ejemplos

En el ejemplo de código siguiente se muestran los miembros A, R, G, B y FromName de un Color y el miembro Implicit.The following code example demonstrates the A, R, G, B, and FromName members of a Color, and the Implicit member.

Este ejemplo está diseñado para usarse con un Windows Form.This example is designed to be used with a Windows Form. Pegue el código en el formulario y llame al método ShowPropertiesOfSlateBlue desde el método de control de eventos Paint del formulario, pasando e como PaintEventArgs.Paste the code into the form and call the ShowPropertiesOfSlateBlue method from the form's Paint event-handling method, passing e as PaintEventArgs.

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");
    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));
}
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

Comentarios

Un color predefinido también se denomina color conocido y se representa mediante un elemento de la enumeración KnownColor.A predefined color is also called a known color and is represented by an element of the KnownColor enumeration. Si el parámetro name no es el nombre válido de un color predefinido, el método FromName crea una estructura Color que tiene el valor ARGB 0 (es decir, todos los componentes ARGB son 0).If the name parameter is not the valid name of a predefined color, the FromName method creates a Color structure that has an ARGB value of 0 (that is, all ARGB components are 0).

Se aplica a