本文整理汇总了C#中System.Drawing.KnownColor枚举的典型用法代码示例。如果您正苦于以下问题:C# KnownColor枚举的具体用法?C# KnownColor怎么用?C# KnownColor使用的例子?那么恭喜您, 这里精选的枚举代码示例或许可以为您提供帮助。
在下文中一共展示了KnownColor枚举的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DisplayKnownColors
private void DisplayKnownColors(PaintEventArgs e)
{
this.Size = new Size(650, 550);
// Get all the values from the KnownColor enumeration.
System.Array colorsArray = Enum.GetValues(typeof(KnownColor));
KnownColor[] allColors = new KnownColor[colorsArray.Length];
Array.Copy(colorsArray, allColors, colorsArray.Length);
// Loop through printing out the values' names in the colors
// they represent.
float y = 0;
float x = 10.0F;
for(int i = 0; i < allColors.Length; i++)
{
// If x is a multiple of 30, start a new column.
if (i > 0 && i % 30 == 0)
{
x += 105.0F;
y = 15.0F;
}
else
{
// Otherwise, increment y by 15.
y += 15.0F;
}
// Create a custom brush from the color and use it to draw
// the brush's name.
SolidBrush aBrush =
new SolidBrush(Color.FromName(allColors[i].ToString()));
e.Graphics.DrawString(allColors[i].ToString(),
this.Font, aBrush, x, y);
// Dispose of the custom brush.
aBrush.Dispose();
}
}