Compartir a través de


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

Para pintar un área con un color sólido, puede usar un pincel predefinido del sistema, como Red o Blue, o puede crear un nuevo SolidColorBrush y describir su Color usando valores de alfa, rojo, verde y azul. En XAML, también puedes pintar un área con un color sólido mediante notación hexadecimal.

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

Ejemplo

Usar un pincel predefinido

En el ejemplo siguiente se usa el pincel Blue predefinido para pintar un rectángulo azul.

<Rectangle Width="50" Height="50" Fill="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;

Uso de notación hexadecimal

En el ejemplo siguiente se usa la notación hexadecimal de 8 dígitos para pintar un rectángulo 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" />

Uso de valores ARGB

En el ejemplo siguiente se crea un SolidColorBrush y se describe su 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>
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 ver otras formas de describir el color, consulte la Color estructura .

temas relacionados

Para obtener más información sobre SolidColorBrush y ejemplos adicionales, consulte la introducción a la pintura con colores sólidos y degradados .

Este ejemplo de código forma parte de un ejemplo más grande proporcionado para la SolidColorBrush clase . Para obtener el ejemplo completo, consulte el Ejemplo de pinceles.

Consulte también