Comment : peindre une zone avec une couleur unie

Pour peindre une zone avec une couleur unie, vous pouvez utiliser un pinceau système prédéfini, tel que Red ou Blue, ou vous pouvez créer une nouvelle SolidColorBrush zone et la décrire Color à l’aide de valeurs alpha, rouge, vert et bleu. En XAML, vous pouvez également peindre une zone avec une couleur unie à l’aide de la notation hexadécimale.

Les exemples suivants utilisent chacune de ces techniques pour peindre un Rectangle bleu.

Exemple

Utilisation d’un pinceau prédéfini

Dans l’exemple suivant, le pinceau Blue prédéfini permet de peindre un rectangle bleu.

<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;

Utilisation de la notation hexadécimale

L’exemple suivant utilise une notation hexadécimale à 8 chiffres pour peindre un rectangle en bleu.

<!-- 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" />

Utilisation de valeurs ARGB

L’exemple suivant crée une SolidColorBrush valeur et décrit son Color utilisation des valeurs ARVB pour la couleur bleue.

<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;

Pour obtenir d’autres façons de décrire la couleur, consultez la Color structure.

Rubriques connexes

Pour plus d’informations sur SolidColorBrush et d’autres exemples, consultez la vue d’ensemble de la peinture avec des couleurs solides et des dégradés.

Cet exemple de code fait partie d’un exemple plus grand fourni pour la SolidColorBrush classe. Pour l’exemple complet, consultez Exemples de pinceaux.

Voir aussi