实现效果:
知识运用:
Point类的构造方法
Size类的构造方法
ControlCollection类的Add方法
实现代码:
private void pictureBox1_MouseClick(object sender, MouseEventArgs e) { Point myPoint = new Point(e.X,e.Y); PictureBox pic = new PictureBox(); pic.BackColor = Color.Transparent; pic.Location = myPoint; pic.SizeMode = PictureBoxSizeMode.StretchImage; switch(flag) { case 0: pic.Size=new Size(18,18); pic.Image = Properties.Resources._1; break; case 1: pic.Size = new Size(24, 24); pic.Image = Properties.Resources._3; break; case 3: pic.Size = new Size(30, 30); pic.Image = Properties.Resources._5; break; } if (e.Button == MouseButtons.Right) { pictureBox1.Controls.Add(pic); } }