怎么动态添加很多控件.并且确定控件的位置.内详.. 我想吧摄像头的视频流的每一个帧都单独显示在一个pictureBox上.类似人家视频编辑软件那样.我怎么动态的添加pictureBox/并且一个接一个的排列起来.并且为每个pictureBox添加一些事件? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 往窗体上添加控件是this.Controls.Add(实例名)呵呵 参考一下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 比如label1吧,this.label1.Location = new System.Drawing.Point(8, 8);这个可以编程控制,这个坐标是相对容器的,如果容器是frame1,那就是frame里面的坐标,panel的就是panel的,同理用其他控件做容器就是相对那个控件实例的 这些是编程的问题啦,用算法规划一下吧,复习一下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(实例名);,然后再在数组中删除它,然后再根据你的需要调整各个图片的位置咯。而触发事件,你都可以绑到同一个方法上去,每个图片触发这个事件时都会对自身调用这个方法。 一个很无解的问题 请教:C#表转换为对象 关于DataGrid绑定DropDownList GridView 前几列固定 后边列可以拖动 怎么实现? PDFCreator转换图片为PDF时,有的旋转了90度 如何在Access中動態添加表?(緊急求助啊~~~) 用.NET的安装项目打包程序时,如何更改其中的默认安装路径?? C#中如何进行位(字节中的位)的存储与读取啊??? 哪位大哥有文件格式的例子,比如我有一堆数据想生成一个Excel格式或者word格式 一个很现实的问题? C#编写的DLL如何注册,让别的程序调用?在线等。 如何增加ListViewItem的间隔距离
呵呵
#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
this.label1.Location = new System.Drawing.Point(8, 8);
这个可以编程控制,这个坐标是相对容器的,
如果容器是frame1,那就是frame里面的坐标,panel的就是panel的,同理用其他控件做容器就是相对那个控件实例的
相对父容器的位置用变量名.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(实例名);,然后再在数组中删除它,然后再根据你的需要调整各个图片的位置咯。而触发事件,你都可以绑到同一个方法上去,每个图片触发这个事件时都会对自身调用这个方法。