本文整理匯總了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();
}
}