Stacklysm

DrawTest2

Sep 28th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Threading;
  6. using System.Windows.Forms;
  7.  
  8. namespace WindowsFormsApplication2
  9. {
  10.     public partial class Form1 : Form
  11.     {
  12.         public Form1()
  13.         {
  14.             InitializeComponent();
  15.         }
  16.  
  17.         private bool move = false;
  18.         private Point location = new Point(0, 0);
  19.         private Point init = new Point(0, 0);
  20.  
  21.         private void Form1_Paint(object sender, PaintEventArgs e)
  22.         {
  23.             MessageBox.Show("A");
  24.  
  25.             if(move)
  26.             {
  27.                 Graphics g = e.Graphics;
  28.                 Pen p = new Pen(Color.Black, 5f);
  29.  
  30.                 g.DrawRectangle(p, new Rectangle(init, new Size(50, 50)));
  31.  
  32.                 while(location.X != init.X && location.Y != init.Y)
  33.                 {
  34.                     if(location.X < init.X)
  35.                     {
  36.                         init.X--;
  37.                     }
  38.                     else if (location.X > init.X)
  39.                     {
  40.                         init.X++;
  41.                     }
  42.  
  43.                     if(location.Y < init.Y)
  44.                     {
  45.                         init.Y--;
  46.                     }
  47.                     else if (location.Y > init.Y)
  48.                     {
  49.                         init.Y++;
  50.                     }
  51.  
  52.                     Thread.Sleep(500);
  53.                 }
  54.  
  55.                 g.Dispose();
  56.                 p.Dispose();
  57.             }
  58.         }
  59.  
  60.         private void panel1_Click(object sender, EventArgs e)
  61.         {
  62.             if(!move)
  63.             {
  64.                 move = true;
  65.                 Refresh();
  66.             }
  67.             else
  68.             {
  69.                 move = false;
  70.             }
  71.         }
  72.  
  73.         private void panel1_MouseMove(object sender, MouseEventArgs e)
  74.         {
  75.             init = e.Location;
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment