2

我想在我的应用程序中为用户创建一种功能,以便在用户每次单击主图片框时创建图片框(我想保留图片框并为用户提供无限图片框创建能力)

编码:

PictureBox Pic = new PictureBox();
Pic = pictureBox2;
Pic.Left = e.X;
Pic.Top = e.Y;
Pic.Visible = true;
4

1 回答 1

3

您需要注册点击事件pictureBox并在点击它时创建一个新事件pirtureBox

     this.pictureBox1 = new System.Windows.Forms.PictureBox();
     this.pictureBox1.Location = new System.Drawing.Point(319, 32);
     this.pictureBox1.Name = "pictureBox1";
     this.pictureBox1.Size = new System.Drawing.Size(100, 50);
     this.pictureBox1.TabIndex = 7;
     this.pictureBox1.TabStop = false;
     // THE IMAGE IS UP TO YOU TO ADD.USE THIS -this.pictureBox1.Image = 
     this.pictureBox1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseClick);
     this.Controls.Add(pb);

并在pictureBox1_MouseClick事件中做:

  private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
  {
     PictureBox pb = new System.Windows.Forms.PictureBox();
     pb.Location = new System.Drawing.Point(319, 32);// THE LOCATION AND CONTEXT IS UP TO YOU
     pb.Name = "pictureBox1";
     pb.Size = new System.Drawing.Size(100, 50);
     pb.TabIndex = 7;
     pb.TabStop = false;
     this.Controls.Add(this.pictureBox1);
  }

好吧,我在这里添加 rene 在评论中说,如果您使用大图片或大量图片,您可能会很快耗尽内存。在这种情况下,您应该.Dispose()对不再需要的图片进行处理

于 2013-09-15T09:34:45.987 回答