我想吧摄像头的视频流的每一个帧都单独显示在一个pictureBox上.类似人家视频编辑软件那样.我怎么动态的添加pictureBox/并且一个接一个的排列起来.并且为每个pictureBox添加一些事件?

解决方案 »

  1.   

    往窗体上添加控件是this.Controls.Add(实例名)
    呵呵
      

  2.   

    参考一下VS自动生成的代码:
    #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.label1 = new System.Windows.Forms.Label();
    this.textBox1 = new System.Windows.Forms.TextBox();
    this.SuspendLayout();
    // 
    // label1
    // 
    this.label1.Location = new System.Drawing.Point(8, 8);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(64, 23);
    this.label1.TabIndex = 0;
    this.label1.Text = "label1";
    // 
    // textBox1
    // 
    this.textBox1.Location = new System.Drawing.Point(32, 88);
    this.textBox1.Name = "textBox1";
    this.textBox1.Size = new System.Drawing.Size(200, 21);
    this.textBox1.TabIndex = 1;
    this.textBox1.Text = "textBox1";
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(432, 266);
    this.Controls.Add(this.textBox1);
    this.textBox1.Controls.Add(this.label1);//这里是把textBox1当作容器
    //this.Controls.Add(this.label1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false); }
    #endregion
      

  3.   

    比如label1吧,
    this.label1.Location = new System.Drawing.Point(8, 8);
    这个可以编程控制,这个坐标是相对容器的,
    如果容器是frame1,那就是frame里面的坐标,panel的就是panel的,同理用其他控件做容器就是相对那个控件实例的
      

  4.   

    这些是编程的问题啦,用算法规划一下吧,复习一下c语言的内容。
    相对父容器的位置用变量名.Size = new System.Drawing.Size(200, 21);来控制。
    有 容器标识.Controls.Add(this.label1);
    就有 容器标识.Controls.Remove(this.label1);
    下面是sdk上的例子。
    // C#
    private void removeControl(object sender, System.EventArgs e)
    {
    // NOTE: The code below uses the instance of 
    // the button (newPanelButton) from the previous example.
       if(panel1.Controls.Contains(newPanelButton))
       {
          this.newPanelButton.Click -= new System.EventHandler(this. 
             NewPanelButton_Click);
          panel1.Controls.Remove(newPanelButton);
          newPanelButton.Dispose();
       }
    }呵呵,触发事件是可以绑上去的嘛,微软是这么做的
    this.实例名.事件+= new System.EventHandler(方法名1); //事件比如为TextChanged 
    private void 方法名1(object sender, System.EventArgs e)
    {
        
    }
    而且可以+= 多个,它们是按+=的先后顺序执行的,而且还可以通过 -= 去掉。你可以用一个类结构数组,里面有一个变量记录这些图片的引用,(具体也就是令它等于那个实例)然后比如他们的初始地址横坐标动态负值为 ( i - 1 ) * 图片宽,而删除一个图片时后先
    容器标识.Controls.Remove(实例名);,然后再在数组中删除它,然后再根据你的需要调整各个图片的位置咯。而触发事件,你都可以绑到同一个方法上去,每个图片触发这个事件时都会对自身调用这个方法。