绘制两个圆圈,其中一个随机移动.. [英] Drawing tow circles ,one of them moves random..

查看:126
本文介绍了绘制两个圆圈,其中一个随机移动..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用c#绘制两个圆圈,其中一个随机移动,第二个圆圈用户尝试跟踪第一个 

how to draw tow circles using c# , one of them moves random , and second circle user trying track first one 

推荐答案

嗨Eslam,

Hi Eslam,

请参考以下演示:

    public partial class Form4 : Form
    {
        public Form4()
        {
            InitializeComponent();
        }

        private void Form4_Load(object sender, EventArgs e)
        {
            g = this.CreateGraphics();
            pen = new Pen(Brushes.Red);
            random = new Random();
            Timer timer = new Timer();
            timer.Interval = 1000;
            timer.Tick += Timer_Tick;
            timer.Start();
        }

        Graphics g = null, g3 = null;
        Pen pen = null, pen2 = null;
        Random random = null;

        private void Timer_Tick(object sender, EventArgs e)
        {
            using (Graphics g2 = this.CreateGraphics())
            {
                g2.Clear(SystemColors.Control);
            }
            int x = random.Next(0, this.Width - 100);
            int y = random.Next(0, this.Height - 150);
            g.DrawEllipse(pen, x, y, 80, 100);
        }

        bool down = false;

        private void Form4_MouseDown(object sender, MouseEventArgs e)
        {
            pen2 = new Pen(Brushes.Blue);
            g3 = pictureBox1.CreateGraphics();
            g3.DrawEllipse(pen2, 0, 0, 80, 100);
            down = true;
        }

        private void Form4_MouseUp(object sender, MouseEventArgs e)
        {
            down = false;
        }

        private void Form4_MouseMove(object sender, MouseEventArgs e)
        {
            if (down == true)
            {
                pictureBox1.Left = e.X;
                pictureBox1.Top = e.Y;
            }
        }
    }

问候,

Frankie


这篇关于绘制两个圆圈,其中一个随机移动..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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