コード例 #1
0
 /// <summary>Method: pnlField_MouseDown
 /// check if mouse is over piece and set variable to
 /// enable piece to be moved
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void pnlField_MouseDown(object sender, MouseEventArgs e)
 {
     currentPosition = new Point(e.X, e.Y);
     if (e.Button == MouseButtons.Right)
     {
         return;
     }
     if (e.Button == MouseButtons.Left)
     {
         topPiece = null;
         ArrayList pl = model.PieceList;
         for (int i = pl.Count; i > 0; i--)
         {
             APiece p = (APiece)pl[i - 1];
             Point  m = new Point(e.X, e.Y);
             if (p.HitTest(m))
             {
                 dragging    = true;
                 p.Highlight = true;
                 topPiece    = p;
                 model.BringToFront(topPiece);
                 break;
             }
         }
         try
         {
             APiece pre;
             if (topPiece != null)
             {
                 pre = (APiece)pl[pl.Count - 2];
             }
             else
             {
                 pre = (APiece)pl[pl.Count - 1];
             }
             pre.Highlight = false;
         }
         catch (ArgumentOutOfRangeException) { }
         RefreshView();
     }
 }
コード例 #2
0
 /// <summary>Method: pnlField_MouseClick
 /// Check the right click menu and set variable to edit status
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void pnlField_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         return;
     }
     if (txtNumber.Visible)
     {
         changePlayerNumber(); // A way to finish editing Number of the editPiece
     }
     if (txtName.Visible)
     {
         changePlayerName(); // A way to finish editing Name of the editPiece
     }
     if (e.Button == MouseButtons.Right)
     {
         mouseLocation = e.Location;
         checkMenuItems();
         editPiece = null;
         ArrayList pl = model.PieceList;
         for (int i = pl.Count; i > 0; i--)
         {
             APiece p = (APiece)pl[i - 1];
             Point  m = new Point(e.X, e.Y);
             if (p.HitTest(m))
             {
                 p.Highlight = true;
                 editPiece   = p;
                 model.BringToFront(p);
                 break;
             }
         }
         try
         {
             APiece pre;
             if (editPiece != null)
             {
                 pre = (APiece)pl[pl.Count - 2];
             }
             else
             {
                 pre = (APiece)pl[pl.Count - 1];
             }
             pre.Highlight = false;
         }
         catch (ArgumentOutOfRangeException) { }
         RefreshView();
         // Control the content menu
         Point pt = pnlField.PointToScreen(e.Location);
         if (editPiece == null)
         {
             pt = pnlField.PointToScreen(e.Location);
             cmsField.Show(pt);
         }
         else if (editPiece is Player)
         {
             checkColorChecked();
             cmsPlayer.Show(pt);
         }
         else if (editPiece is Referee)
         {
             cmsReferee.Show(pt);
         }
         else if (editPiece is Ball)
         {
             checkBallTypeChecked();
             cmsBall.Show(pt);
         }
     }
 }