Color.FromName(String) Метод
Определение
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
Параметры
- name
- String
Строка, которая является именем предопределенного цвета.A string that is the name of a predefined color. Допустимые имена те же, что и у элементов перечня KnownColor.Valid names are the same as the names of the elements of the KnownColor enumeration.
Возвращаемое значение
Объект Color, создаваемый данным методом.The Color that this method creates.
Примеры
В следующем примере кода демонстрируются A элементы,, R G , и элемента B FromName Color , и Implicit .The following code example demonstrates the A, R, G, B, and FromName members of a Color, and the Implicit member.
Этот пример предназначен для использования с Windows Form.This example is designed to be used with a Windows Form. Вставьте код в форму и вызовите ShowPropertiesOfSlateBlue
метод из формы Paint метода обработки событий, передав его e
как 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
Комментарии
Стандартный цвет также называется известным цветом и представляется элементом KnownColor перечисления.A predefined color is also called a known color and is represented by an element of the KnownColor enumeration. Если name
параметр не является допустимым именем предопределенного цвета, FromName метод создает Color структуру, ИМЕЮЩую значение ARGB, равное 0 (то есть все компоненты ARGB равны 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).