Martin
Martin

Reputation: 40365

Is there an online example of all the colours in System.Drawing.Color?

Can anyone point me to a reference chart that has swatches of all the colours that are represented in System.Drawing.Color?

Upvotes: 49

Views: 57905

Answers (3)

Mark Davich
Mark Davich

Reputation: 626

Here is a WPF example that produces the list @StayOnTarget uses in their answer:

MainWindow.xaml

<Window
    x:Class="Colors.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Colors"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800"
>
    <Grid>
        <ListBox ItemsSource="{Binding Colors}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                        <Rectangle Width="23" Height="23">
                            <Rectangle.Fill>
                                <SolidColorBrush Color="{Binding Path=Value.Color}" />
                            </Rectangle.Fill>
                        </Rectangle>

                        <TextBlock 
                            Text="{Binding Path=Value}" 
                            FontFamily="Consolas" 
                            FontSize="16"
                            VerticalAlignment="Center"
                            Margin="5 0 0 0" />

                        <TextBlock 
                            Text="{Binding Path=Name}" 
                            FontFamily="Consolas" 
                            FontSize="16"
                            FontWeight="Bold"
                            VerticalAlignment="Center"
                            Margin="5 0 0 0" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Window>

MainWindow.xaml.cs

using System.Windows;
using System.Windows.Media;

namespace Colors
{
    public partial class MainWindow : Window
    {
        public class ColorInfo
        {
            public string Name { get; set; } = string.Empty;
            public SolidColorBrush Value { get; set; } = default!;
        }

        public IEnumerable<ColorInfo> Colors => typeof(Brushes)
            .GetProperties()
            .Where(info => info.PropertyType == typeof(SolidColorBrush))
            .Select(info => new ColorInfo() {
                Name = info.Name,
                Value = (SolidColorBrush)info.GetValue(info, null)!
            })
            .ToList()! ?? Enumerable.Empty<ColorInfo>();

        public MainWindow()
        {
            InitializeComponent();
            DataContext = this; // Needed for binding the ListBox to Colors
        }
    }
}

Upvotes: 1

StayOnTarget
StayOnTarget

Reputation: 13058

From here:

The following image shows the color of each predefined brush, its name, and its hexadecimal value.

May as well have the details right here on SO:

enter image description here

Upvotes: 68

Tim Lloyd
Tim Lloyd

Reputation: 38494

"Web Colors - X11 color names" from wikipedia:

http://en.wikipedia.org/wiki/Web_colors

http://en.wikipedia.org/wiki/X11_color_names

WPF Colors

Color names in Windows Presentation Foundation (WPF) match the color names in Microsoft .NET Framework, Windows Forms, and Microsoft Internet Explorer. These colors and their names are based on the UNIX X11 color values.

http://msdn.microsoft.com/en-us/library/system.windows.media.brushes.aspx

Upvotes: 17

Related Questions