Instrukcje: malowanie obszaru za pomocą koloru stałego
Aby pomalować obszar kolorem jednolitym, można użyć wstępnie zdefiniowanego pędzla systemowego, takiego jak Red lub Blue, albo stworzyć nowy SolidColorBrush i opisać jego Color za pomocą wartości alfa, czerwonej, zielonej i niebieskiej. W języku XAML można również malować obszar o stałym kolorze za pomocą notacji szesnastkowej.
W poniższych przykładach użyto każdej z tych technik do malowania Rectangle niebieskiego.
Przykład
Korzystanie z wstępnie zdefiniowanego pędzla
W poniższym przykładzie użyto wstępnie zdefiniowanego pędzla Blue do malowania prostokąta niebieskiego.
<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;
Używanie notacji szesnastkowej
W następnym przykładzie użyto 8-cyfrowej notacji szesnastkowej do malowania prostokąta niebieskiego.
<!-- 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" />
przy użyciu wartości ARGB
W następnym przykładzie tworzy się SolidColorBrush i opisuje jej Color, przy użyciu wartości ARGB odpowiadających kolorowi niebieskiemu.
<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;
Aby zapoznać się z innymi sposobami opisywania koloru, zobacz Color strukturę.
tematy pokrewne
Aby uzyskać więcej informacji na temat SolidColorBrush i dodatkowych przykładów, zobacz Omówienie malowania przy użyciu kolorów stałych i gradientów.
Ten przykład kodu jest częścią większego przykładu udostępnionego dla klasy SolidColorBrush. Aby zapoznać się z kompletnym przykładem, zobacz przykład Brushes sample.
Zobacz też
.NET Desktop feedback