移动矩形和弧形或其他东西 [英] move rectangle and arc or other thing

查看:87
本文介绍了移动矩形和弧形或其他东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我需要矩形移动和圆弧或其他东西的代码
我已经在中编写了这段代码,因为对象必须移动

Hi I need a code for rectangle move and arc or other thing
I''ve written this code in For the object must move

protected override void OnPaint(PaintEventArgs paintEvent)
{
    // get graphics object

    SolidBrush brush = new SolidBrush(Color.Blue);
    Pen pen = new Pen(Color.AliceBlue);
    Rectangle rectangle1 = new Rectangle( 400, 250, 25, 25 );//rectangle for circle
    g.DrawRectangle(pen, 30, 20, 450, 280);
    g.DrawArc(pen, rectangle1, 0, 360);//circle

}

private void button1_Click(object sender, EventArgs e)
{
    for (int i = 0; i < 100; i++)
         //move

}

推荐答案

您要做的就是将DrawRectangle中的固定坐标更改为变量,然后更改变量.
All you have to do is change the fixed coordinates in your DrawRectangle to variables, and alter the variables.:

private int rectLeft = 20;
private int rectTop = 30;

        protected override void OnPaint(PaintEventArgs paintEvent)
        {
            Graphics g = paintEvent.Graphics;
            Pen pen = new Pen(Color.AliceBlue);
            g.DrawRectangle(pen, rectLeft, rectTop, 450, 280);
            pen.Dispose();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
        rectLeft += 20;
        rectTop += 10;
        Invalidate();
        }

(我将您的代码缩减了一些以使其更清晰)

请注意,您有责任处置自己创建的所有笔,刷子等!否则将导致看似奇怪的问题...

(I cut your code down a little to make it clearer)

Note that you are responsible for disposing any pens, brushes, etc. you create! Failure to do so will result in odd seeming problems...


这篇关于移动矩形和弧形或其他东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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