方法 : 純色で領域を塗りつぶす

純色で領域を塗りつぶすには、RedBlue などの定義済みのシステム ブラシを使用します。または、新しい SolidColorBrush を作成し、アルファ、赤、緑、および青の値を使用して Color を記述することもできます。 XAML では、16 進数表記を使用して純色で領域を塗りつぶすこともできます。

これらの各手法を使用して Rectangle を青で塗りつぶす例を次に示します。

使用例

定義済みブラシの使用

次の例では、定義済みブラシ Blue を使用して、四角形を青で塗りつぶします。

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

16 進数表記の使用

次の例では、8 桁の 16 進数表記を使用して、四角形を青で塗りつぶします。

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

ARGB 値の使用

次の例では SolidColorBrush を作成し、その Color を青い色に対応する ARGB 値を使用して記述します。

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

色を記述するその他の方法については、Color 構造体を参照してください。

関連トピック

SolidColorBrush およびその他の例の詳細については、「純色およびグラデーションによる塗りつぶしの概要」の概要を参照してください。

このコード例は、SolidColorBrush クラスのトピックで取り上げているコード例の一部分です。 サンプル全体については、ブラシのサンプルを参照してください。

参照

参照

Brushes