예제 #1
0
 private void Form1_MouseDown(object sender, MouseEventArgs e)
 {
     if (sender.GetType().Equals(typeof(Peça)) && e.Button == MouseButtons.Left)
     {
         atual = sender as Peça;
         atual.BringToFront();
         criaListaPecas();
         if (atual.Down(e.Location))
         {
             _Offset = new Point(e.X, e.Y);
             canMove = true;
             other   = false;
         }
         else
         {
             Console.WriteLine(peças[1].PointToClient(new Point(e.X + atual.Location.X, e.Y + atual.Location.Y)));
             Console.WriteLine(atual.Location);
             Point p = new Point();
             if (peças[1].ClientRectangle.Contains(peças[1].PointToClient(new Point(e.X + atual.Location.X, e.Y + atual.Location.Y))) &&
                 peças[1].Down(peças[1].PointToClient(new Point(e.X + atual.Location.X, e.Y + atual.Location.Y))))
             {
                 p     = peças[1].PointToClient(new Point(e.X + atual.Location.X, e.Y + atual.Location.Y));
                 atual = peças[1];
                 atual.BringToFront();
                 criaListaPecas();
                 _Offset = p;
                 canMove = true;
                 other   = true;
             }
             else if (peças[2].ClientRectangle.Contains(peças[2].PointToClient(new Point(e.X + atual.Location.X, e.Y + atual.Location.Y))) &&
                      peças[2].Down(peças[2].PointToClient(new Point(e.X + atual.Location.X, e.Y + atual.Location.Y))))
             {
                 p     = peças[2].PointToClient(new Point(e.X + atual.Location.X, e.Y + atual.Location.Y));
                 atual = peças[2];
                 atual.BringToFront();
                 criaListaPecas();
                 _Offset = p;
                 canMove = true;
                 other   = true;
             }
             else if (peças[3].ClientRectangle.Contains(peças[3].PointToClient(new Point(e.X + atual.Location.X, e.Y + atual.Location.Y))) &&
                      peças[3].Down(peças[3].PointToClient(new Point(e.X + atual.Location.X, e.Y + atual.Location.Y))))
             {
                 p     = peças[3].PointToClient(new Point(e.X + atual.Location.X, e.Y + atual.Location.Y));
                 atual = peças[3];
                 atual.BringToFront();
                 criaListaPecas();
                 _Offset = p;
                 canMove = true;
                 other   = true;
             }
         }
     }
 }