Share via


Cómo: Pintar un área con un color sólido

Para pintar una área con un color sólido, puede utilizar un pincel predefinido del sistema, como Red o Blueo puede crear un nuevo SolidColorBrush y describir su propiedad Color mediante sus valores de alfa, rojo, verde y azul. En XAML, puede pintar también una área con un color sólido utilizando la notación hexadecimal.

En los ejemplos siguientes se utilizan cada una de estas técnicas para pintar un objeto Rectangle de azul.

Ejemplo

Utilizar un pincel predefinido

En el ejemplo siguiente se utiliza la propiedad Blue del pincel predefinido para pintar un rectángulo de azul.

<Rectangle Width="50" Height="50" Fill="Blue" />
            ' Create a rectangle and paint it with
            ' a predefined brush.
            Dim myPredefinedBrushRectangle As New Rectangle()
            myPredefinedBrushRectangle.Width = 50
            myPredefinedBrushRectangle.Height = 50
            myPredefinedBrushRectangle.Fill = Brushes.Blue
// Create a rectangle and paint it with
// a predefined brush.
Rectangle myPredefinedBrushRectangle = new Rectangle();
myPredefinedBrushRectangle.Width = 50;
myPredefinedBrushRectangle.Height = 50;
myPredefinedBrushRectangle.Fill = Brushes.Blue;

Utilizar la notación hexadecimal

En el ejemplo siguiente se utiliza la notación hexadecimal de 8 dígitos para pintar un rectángulo de azul.

<!-- Note that the first two characters "FF" of the 8-digit
     value is the alpha which controls the transparency of 
     the color. Therefore, to make a completely transparent
     color (invisible), use "00" for those digits (e.g. #000000FF). -->
<Rectangle Width="50" Height="50" Fill="#FF0000FF" />

Utilizar los valores ARGB

En el ejemplo siguiente se crea un objeto SolidColorBrush y se describe su propiedad Color utilizando los valores ARGB para el color azul.

<Rectangle Width="50" Height="50">
  <Rectangle.Fill>
    <SolidColorBrush>
     <SolidColorBrush.Color>

        <!-- Describes the brush's color using
             RGB values. Each value has a range of 0-255.  
             R is for red, G is for green, and B is for blue.
             A is for alpha which controls transparency of the
             color. Therefore, to make a completely transparent
             color (invisible), use a value of 0 for Alpha. -->
        <Color A="255" R="0" G="0" B="255" />
     </SolidColorBrush.Color>
    </SolidColorBrush>
  </Rectangle.Fill>
</Rectangle>
            Dim myRgbRectangle As New Rectangle()
            myRgbRectangle.Width = 50
            myRgbRectangle.Height = 50
            Dim mySolidColorBrush As New SolidColorBrush()

            ' Describes the brush's color using RGB values. 
            ' Each value has a range of 0-255.
            mySolidColorBrush.Color = Color.FromArgb(255, 0, 0, 255)
            myRgbRectangle.Fill = mySolidColorBrush
Rectangle myRgbRectangle = new Rectangle();
myRgbRectangle.Width = 50;
myRgbRectangle.Height = 50;
SolidColorBrush mySolidColorBrush = new SolidColorBrush();

// Describes the brush's color using RGB values. 
// Each value has a range of 0-255.
mySolidColorBrush.Color = Color.FromArgb(255, 0, 0, 255);
myRgbRectangle.Fill = mySolidColorBrush;           

Para obtener otras maneras de describir colores, vea la estructura Color.

Temas relacionados

Para obtener más información acerca de SolidColorBrush y más ejemplos, vea Información general sobre el dibujo con colores sólidos y degradados.

Este ejemplo de código forma parte de un ejemplo más extenso referente a la clase SolidColorBrush. Para obtener el ejemplo completo, vea Brushes Sample.

Vea también

Referencia

Brushes