コード例 #1
0
        /// <summary>
        /// 点击棋子事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Piece_Click(object sender, EventArgs e)
        {
            PieceControl p = (PieceControl)sender;

            MessageBox.Show(string.Format("我是:{0}", p.Text));
        }
コード例 #2
0
 /// <summary>
 /// 初始化开始信息
 /// </summary>
 public void InitStartInfo()
 {
     if (ArrPiece != null)
     {
         this.Controls.Clear();
         string[] arrTmp0 = new string[9] {
             "車", "馬", "象", "士", "将", "士", "象", "馬", "車"
         };
         string[] arrTmp1 = new string[9] {
             "車", "馬", "相", "仕", "帅", "仕", "相", "馬", "車"
         };
         int   radius    = 45;
         Color backColor = Color.Gold;
         for (int i = 0; i < 9; i++)
         {
             PieceControl p0 = new PieceControl()
             {
                 Text      = arrTmp0[i],
                 BackColor = backColor,
                 PieceInfo = ArrPiece[i, 0],
                 Width     = radius,
                 Height    = radius
             };
             p0.Click += Piece_Click;
             this.Controls.Add(p0);
             PieceControl p1 = new PieceControl()
             {
                 Text      = arrTmp1[i],
                 BackColor = backColor,
                 PieceInfo = ArrPiece[i, 9],
                 Width     = radius,
                 Height    = radius
             };
             p1.Click += Piece_Click;
             this.Controls.Add(p1);
         }
         //炮
         for (int i = 0; i < 2; i++)
         {
             PieceControl p0 = new PieceControl()
             {
                 Text      = "炮",
                 BackColor = backColor,
                 PieceInfo = ArrPiece[i * 6 + 1, 2],
                 Width     = radius,
                 Height    = radius
             };
             p0.Click += Piece_Click;
             this.Controls.Add(p0);
             PieceControl p1 = new PieceControl()
             {
                 Text      = "炮",
                 BackColor = backColor,
                 PieceInfo = ArrPiece[i * 6 + 1, 7],
                 Width     = radius,
                 Height    = radius
             };
             p1.Click += Piece_Click;
             this.Controls.Add(p1);
         }
         //兵和卒
         for (int i = 0; i < 5; i++)
         {
             PieceControl p0 = new PieceControl()
             {
                 Text      = "卒",
                 BackColor = backColor,
                 PieceInfo = ArrPiece[i * 2, 3],
                 Width     = radius,
                 Height    = radius
             };
             p0.Click += Piece_Click;
             this.Controls.Add(p0);
             PieceControl p1 = new PieceControl()
             {
                 Text      = "兵",
                 BackColor = backColor,
                 PieceInfo = ArrPiece[i * 2, 6],
                 Width     = radius,
                 Height    = radius
             };
             p1.Click += Piece_Click;
             this.Controls.Add(p1);
         }
     }
 }