有System.Drawing.Color中所有颜色的在线示例吗?

问题描述 投票:0回答:3

任何人都可以向我指出一个参考图表,其中包含 System.Drawing.Color 中表示的所有颜色的样本吗?

c# user-interface system.drawing.color
3个回答
66
投票

从这里:

下图显示了每个预定义画笔的颜色,其 名称及其十六进制值。

也可以在此处提供详细信息:

enter image description here


17
投票

来自维基百科的“Web Colors - X11 颜色名称”:

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

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

WPF 颜色

Windows Presentation Foundation (WPF) 中的颜色名称与 Microsoft .NET Framework、Windows Forms 和 Microsoft Internet Explorer 中的颜色名称相匹配。这些颜色及其名称基于 UNIX X11 颜色值。

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


0
投票

这是一个 WPF 示例,它生成 @StayOnTarget 在其答案中使用的列表:

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
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.