动态地向表单添加按钮 [英] Adding buttons to the form dynamically
问题描述
在C#SHARP中需要帮助??
我一直在使用c sharp进行项目我试图在用户单击按钮时在表单中添加按钮添加更多。
我将如何动态地向表格中的面板添加按钮(新按钮)应该放在下一行。
HELP NEEDED IN C# SHARP??
I have been working on a project in c sharp i am trying to add buttons to the panel in my form when the user clicks a button "add more".
How will i do that add buttons to the panel in the form dynamically that (new button) should be placed on nextline.
推荐答案
C#SHARP需要帮助吗?
我一直在研究c项目我试图在用户单击按钮添加更多时在我的表单中添加按钮。
我将如何在表单中添加按钮到面板动态地(新按钮)应放在下一行。
HELP NEEDED IN C# SHARP??
I have been working on a project in c sharp i am trying to add buttons to the panel in my form when the user clicks a button "add more".
How will i do that add buttons to the panel in the form dynamically that (new button) should be placed on nextline.
按钮aButton = new Button();
aButton.Name =" Button" ;; //你也可以设置高度
targetPanel.Controls.Add(aButton);
干杯。
Button aButton = new Button();
aButton.Name = "Button"; //you also can set height width
targetPanel.Controls.Add(aButton);
Cheers.
按钮aButton = new Button();
aButton.Name =" Button" ;; //你也可以设置高度
targetPanel.Controls.Add(aButton);
干杯。
Button aButton = new Button();
aButton.Name = "Button"; //you also can set height width
targetPanel.Controls.Add(aButton);
Cheers.
你是对的,但这只会动态创建一个按钮
我想创建按钮,只要用户想要
我发布了我的代码,它将向表单面板添加一个文本框和一个标签
它只打印一个文本框并动态标记
private void button1_Click(object sender,EventArgs e)
{
j = j + 25; //增加labael和文本框的位置
this.textbox2.Size = new System.Drawing.Size(75,20);
this.textbox2.Location = new System.Drawing.Point(91,j);
this.textbox2.Name.Equals(" textbox" + i);
this.label2.AutoSize = true;
this.label2 .Location = new System.Drawing.Point(13,j);
this.label2.Name.Equals(" Enter number" + i);
this。 label2.Size = new System.Drawing.Si ze(72,13);
this.label2.Text =" Enter Number" + i;
this.panel1.Controls.Add(this.textbox2);
this.panel1.Controls.Add(this.label2);
i ++; //增加标签添加的文本框数
}
[IMG] C:\文档和设置\ NOUMANAN \Desktop \untitled.bmp [/ IMG]
You r right but this only creates one button dynamically
I want to create buttons as long as user wants
I am posting my code that will add a textbox and a label to the panel of the form
It only prints one textbox and and label dynamically
private void button1_Click(object sender, EventArgs e)
{
j = j + 25;// increment the position of the labael and text box
this.textbox2.Size = new System.Drawing.Size(75, 20);
this.textbox2.Location = new System.Drawing.Point(91, j);
this.textbox2.Name.Equals("textbox" + i);
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(13, j);
this.label2.Name.Equals("Enter number" + i);
this.label2.Size = new System.Drawing.Size(72, 13);
this.label2.Text = "Enter Number" + i;
this.panel1.Controls.Add(this.textbox2);
this.panel1.Controls.Add(this.label2);
i++;//increments the number of textbox an label added
}
[IMG]C:\Documents and Settings\NOUMAN\Desktop\untitled.bmp[/IMG]
你的意思是只动态创建一个按钮?
动态创建一个按钮你调用那段代码的次数,例如每次点击一次按钮。
我看到你的代码实际上并没有创建一个新的文本框和标签,而是在一些现有的代码中移动。确保实际创建所需控件的新实例。
What do you mean only creates one button dynamically?
It will make one button dynamically as many times as you call that code, for example on every button click.
I see your code does not actually create a new textbox and label but mearly move around some existing ones. Be sure to actually create NEW instances of the controls you want.
这篇关于动态地向表单添加按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!