用如下代码动态生成picturebox,我想达到按一次button就动态生成一个picturebox,而且没次生成的picturebox之间的距离都一定:
private void btn_Click(object sender, System.EventArgs e)
{
//动态生成PictureBox
PictureBox pb =new PictureBox();
pb.Size=this.pBx_02.Size;
pb.Location=new Point(this.pBx_02.Location.X+this.pBx_02 .Width +20,this.pBx_02 .Size .Width );
pb.Image =Image.FromFile(Application.StartupPath+@"\背景图片\卷2.jpg") ;
this.Controls.Add(pb);
}
应该怎么该代码,谢谢!

解决方案 »

  1.   

    using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Data; 
    using System.Drawing; 
    using System.Text; 
    using System.Windows.Forms;
    namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private int i = 0;
            private void button1_Click_1(object sender, EventArgs e)
            {
                i++; 
                PictureBox pb = new PictureBox();
                pb.Image =Image.FromFile(Application.StartupPath+@"\背景图片\卷2.jpg") ; 
                flowLayoutPanel1.Controls.Add(pb);
            }
        }
    }用到FLOWLAYOUTPANEL
      

  2.   

    不好意思
    上面有代码忘记删了.
    private int i = 0; 
    i++;
    这二行没用.
      

  3.   

    你的意思就是加一个控件panl是么。不想那么做