贤人必须成人,成人才能达己.

共同进步

  :: :: 博问 :: 闪存 :: 新随笔 :: :: :: 管理 ::

 private void InitGroupBox()
        {
            for (int k = 0; k < 16;k++ )
            {
                PictureBox pic = new PictureBox();
                int i = k % 4;
                int j = k / 4;
                pic.Name = k.ToString();
                pic.Top = 50 + j * 201;
                pic.Left = 50+i * 251;
                pic.Width = 250;
                pic.Height = 200;
                //pic.Visible = true;
                pic.Click  += new EventHandler(PictureBox_Click);
                pic.Paint += new PaintEventHandler(pictureBox_Paint);
                pic.BorderStyle = BorderStyle.FixedSingle;
                this.GroupPanel.Controls.Add(pic);
            }
        }
        private void PictureBox_Click(object sender, EventArgs e)
        {
            PictureBox p = (PictureBox)sender;
            if (p == old) return;

            if (old != null)
            {
                old.Width -= 10;
                old.Height -= 10;
                old.Location = new Point(old.Location.X + 5, old.Location.Y + 5);
            }

            old = p;
            p.Width += 10;
            p.Height += 10;
            p.Location = new Point(p.Location.X - 5, p.Location.Y - 5);
            p.BringToFront(); 
          
        }
        private void pictureBox_Paint(object sender, PaintEventArgs e)
        {
            PictureBox p = (PictureBox)sender;
            if (p == old)
            {
                Pen pp = new Pen(Color.Red);
                e.Graphics.DrawRectangle(pp, e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.X + e.ClipRectangle.Width - 1, e.ClipRectangle.Y + e.ClipRectangle.Height - 1);
            }
        } 

posted on 2008-09-10 10:09  adi  阅读(554)  评论(0编辑  收藏  举报