如何使用颜色类型数组的值来为形状着色? [英] How to use the values of color type array to color a shape?

查看:95
本文介绍了如何使用颜色类型数组的值来为形状着色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个颜色类型数组,使得:







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);
        }
    }


这篇关于如何使用颜色类型数组的值来为形状着色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆