serkan sendur
Postaholic
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
Use this code here
private void AddFields()
{
if (ButtonIndex != 11)
{
Button field = new Button();
field.Name = "field" + ButtonIndex.ToString();
ButtonIndex++;
field.Size = new Size(200, 20);
field.Location = new Point(10,10);
}
You will need to add this where you declare your variables
public int ButtonIndex = 1;
If you are creating more then one at diffrent locations then you should use a panel and under properties use the flowdirection property, this will mean it will naturlly flow whatever direction you set it at instead of coding for each button location, you will need to use the following code and replace it with the one that specifies location.
panel1.Controls.Add(field);
Also if you are using more than one and you want to cap how many to generate add this under the if statement
else
{
MessageBox.Show("A Maximum of 10 Areas is Supported");
}
Hope this fixes your problem.
wingers1290
Junior Poster in Training
89 posts since May 2009
Reputation Points: 12
Solved Threads: 0
hey wingers1290, you have to make a citation at least, i remember those codes from some posts that i post to help you, you could post the original instead of chaning the names, avoid plagiarism.
serkan sendur
Postaholic
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
wingers1290
Junior Poster in Training
89 posts since May 2009
Reputation Points: 12
Solved Threads: 0
Ok, firstly you need to retrieve the lsit of button ID's and Descriptions from the database, check out the link Antenka gave you or google for one of the many many tutorials on c# database access.
You said you want to use an array, i'm assuming that will be to store the details of the buttons. Once you have your array you can create the buttons using code similar to that given earlier:
string[] Descriptions = { "One", "Two", "Another Description", "Desc." };
for( int i = 1; i<=Descriptions.Length;i++)
{
Button btn = new Button();
btn.Name = "btn" + i.ToString(); //btn1, btn2, etc
btn.Text = Descriptions[i - 1];
panel1.Controls.Add(btn);
}
Ryshad
Nearly a Posting Virtuoso
1,307 posts since Aug 2009
Reputation Points: 512
Solved Threads: 246