[code=C#]
Button b = new Button();
b.Text = "ddd";
this.Controls.Add(b);
[code]创建一个button 添加到窗体上 应该如何写 ?加上this.ResumeLayout(false); 也不行 上述代码在窗体的构造函数里
Button b = new Button();
b.Text = "ddd";
this.Controls.Add(b);
[code]创建一个button 添加到窗体上 应该如何写 ?加上this.ResumeLayout(false); 也不行 上述代码在窗体的构造函数里
最简单的方式就是,你先拖拽一个button到窗体,然后把所有和这个button的按钮加入到构造函数中,就知道你应该写什么样的代码了
b.Size = new System.Drawing.Size(198, 59);
b.Location = new System.Drawing.Point(1, 1);
b.Text = "ddd";
this.Controls.Add(b);还是不行
FileInfo[] files = picFolder.GetFiles();
int j = 0;
for (int i = 0; i < files.Length; i++)
{
if (files[i].Extension == ".jpg")
{
j++;
Panel p = new Panel();
p.Name = "p" + j;
p.Size = new System.Drawing.Size(198, 59);
p.Location = new System.Drawing.Point(1, 1);
PictureBox pbox = new PictureBox();
pbox.Size = new System.Drawing.Size(198, 59);
pbox.Location = new System.Drawing.Point(1, 1);
pbox.Image = Image.FromFile("pic/" + files[i].Name);
this.Controls.Add(p);
}
}
public Form1()
{
Button b = new Button();
b.Size = new System.Drawing.Size(198, 59);
b.Location = new System.Drawing.Point(1, 1);
b.Text = "ddd";
this.Controls.Add(b); InitializeComponent();
}
你试试这个,我试过可以的
p.Controls.Add(pbox);
{
Button b = new Button();
b.Text="OK";
this.Controls.Add(b);
}
楼主:为什么我这样创建完全没问题那,可以创建BUTTON!
你所有的控件都在同一个位置,当然显示不出了
放到FlowLayoutPanel中试试