Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Threading;
- using System.Windows.Forms;
- namespace WindowsFormsApplication2
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private bool move = false;
- private Point location = new Point(0, 0);
- private Point init = new Point(0, 0);
- private void Form1_Paint(object sender, PaintEventArgs e)
- {
- MessageBox.Show("A");
- if(move)
- {
- Graphics g = e.Graphics;
- Pen p = new Pen(Color.Black, 5f);
- g.DrawRectangle(p, new Rectangle(init, new Size(50, 50)));
- while(location.X != init.X && location.Y != init.Y)
- {
- if(location.X < init.X)
- {
- init.X--;
- }
- else if (location.X > init.X)
- {
- init.X++;
- }
- if(location.Y < init.Y)
- {
- init.Y--;
- }
- else if (location.Y > init.Y)
- {
- init.Y++;
- }
- Thread.Sleep(500);
- }
- g.Dispose();
- p.Dispose();
- }
- }
- private void panel1_Click(object sender, EventArgs e)
- {
- if(!move)
- {
- move = true;
- Refresh();
- }
- else
- {
- move = false;
- }
- }
- private void panel1_MouseMove(object sender, MouseEventArgs e)
- {
- init = e.Location;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment