如何使用颜色类型数组的值来为形状着色?
我有一个颜色类型数组,使得:
colorSet [0] =颜色.DodgerBlue;
colorSet [1] = Color.YellowGreen;
colorSet [2] = Color.Crimson;
colorSet [3] = Color.HotPink;
colorSet [4] = Color.MediumPurple;
colorSet [5] = Color.MediumSeaGreen;
colorSet [6] = Color.MediumVioletRed;
colorSet [7] = Color.PaleVioletRed;
colorSet [8] = Color.Plum;
colorSet [9 ] = Color.SlateBlue;
i想用Color [5]代替Red in以下声明:
DrawEllipse(Pens.Red,50 *我,50 * j,8,8);
怎么办?????????
我尝试过:
i尝试过:
DrawEllipse(Pens.colorSet [5],50 * i,50 * j,8,8);
i have a color type array such that:
colorSet[0] = Color.DodgerBlue;
colorSet[1] = Color.YellowGreen;
colorSet[2] = Color.Crimson;
colorSet[3] = Color.HotPink;
colorSet[4] = Color.MediumPurple;
colorSet[5] = Color.MediumSeaGreen;
colorSet[6] = Color.MediumVioletRed;
colorSet[7] = Color.PaleVioletRed;
colorSet[8] = Color.Plum;
colorSet[9] = Color.SlateBlue;
i want to use Color[5] in place of Red in following statement:
DrawEllipse(Pens.Red, 50 * i, 50 * j, 8, 8);
what to do?????????
What I have tried:
i have tried :
DrawEllipse(Pens.colorSet[5], 50 * i, 50 * j, 8, 8);
这比你认为:颜色和笔是不一样的,而笔是稀缺资源,所以当你使用自己的时候,你有责任在你完成后正确处理它。
That's more complex than you think: a Color and a Pen aren't the same thing, and a Pen is a scarce resource, so when you use your own, you are responsible for Disposing it correctly when you are finished.
private void myPanel_Paint(object sender, PaintEventArgs e)
{
using (Pen p = new Pen(colorSet[5]))
{
e.Graphics.DrawEllipse(p, 50, 50, 8, 8);
}
}