找到选择的绘图形状[或如何选择绘制形状]

时间:2013-12-23 14:31:32

标签: c# drawing

喜欢这个代码我画了一个用键移动和改变颜色的形状,现在我会用鼠标点击改变它的颜色,但我怎么知道我选择的是一个形状?

“Iman Gh”

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {

    public int x = 0, y = 0, wi, hi;
    public int intup, intdown, intleft, intright;
    public Brush bh1 = System.Drawing.Brushes.Blue;
    public Color co1 = System.Drawing.Color.Blue;




    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        this.Paint += new PaintEventHandler(Form1_Paint);
    }

    private void Form1_Paint(object sender, PaintEventArgs e)
    {
        Graphics g = e.Graphics;
        Point point1 = new Point(200 + x, 200 + y);
        Point point2 = new Point(250 + x, 200 + y);
        Point point3 = new Point(275 + x, 170 + y);
        Point point4 = new Point(320 + x, 170 + y);
        Point point5 = new Point(350 + x, 200 + y);
        Point point6 = new Point(400 + x, 200 + y);
        Point point7 = new Point(400 + x, 250 + y);
        Point point8 = new Point(350 + x, 250 + y);
        Point point9 = new Point(250 + x, 250 + y);
        Point point10 = new Point(200 + x, 250 + y);
        Point point11 = new Point(190 + x, 210 + y);
        Point point12 = new Point(190 + x, 240 + y);

        Point[] curvePoints = { point1, point2, point3, point4, point5, point6, point7, point8, point9, point10, point11, point12 };
        g = Form1.ActiveForm.CreateGraphics();

        Pen blackPen = new Pen(Color.Black, 3);
        g.FillPolygon(bh1 , curvePoints);
        g.DrawEllipse(new Pen(co1, 5), 250 + x, 250 + y, 20, 20);
        g.DrawEllipse(new Pen(co1, 5), 350 + x, 250 + y, 20, 20);
        //wi = this.ClientSize.Width - 210;
        //hi = this.ClientSize.Height - 90;
        //control area...
        intup = point3.Y;
        intleft = point11.X;
        intdown = point9.Y + 10;
        intright = point6.X;


    }

    private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        string key;
        key = e.KeyData.ToString();

        if (key == "Up")
        {
            if (intup > 5)
            {
            y = y - 1;
            this.Refresh();
            }
        }
        else if (key == "Down")
        {
            if (intdown < 550)
            {
                y = y + 1;
                this.Refresh();
            }
        }
        else if (key == "Left")
        {
            if (intleft > 5)
            {
                x = x - 1;
                this.Refresh();
            }
        }
        else if (key == "Right")
        {
            if (intright < 980)
            {
                x = x + 1;
                this.Refresh();
            }
        }
        else if (key == "R")
        {
            bh1 = System.Drawing.Brushes.Red;
            co1 = System.Drawing.Color.Red;
            this.Refresh();
        }
        else if (key == "T")
        {
            bh1 = System.Drawing.Brushes.Thistle;
            co1 = System.Drawing.Color.Thistle;
            this.Refresh();
        }
        else if (key == "Y")
        {
            bh1 = System.Drawing.Brushes.Yellow;
            co1 = System.Drawing.Color.Yellow;
            this.Refresh();
        }
        else if (key == "G")
        {
            bh1 = System.Drawing.Brushes.Green;
            co1 = System.Drawing.Color.Green;
            this.Refresh();
        }
        else if (key == "S")
        {
            bh1 = System.Drawing.Brushes.Sienna;
            co1 = System.Drawing.Color.Sienna;
            this.Refresh();
        }
    }
}
 }

0 个答案:

没有答案