Hi All,
I am facing problems with location assigning and click events of dynamically created buttons.
I have a button array which will create the no of buttons dynamically, but i am very confused to assigning the location according to the form size horizontally and vertically and the click event of these dynamically created buttons.
For loading the buttons dynamically i wrote like this.
private void frmResturantTables_Load(object sender, EventArgs e)
{
createTables(50);
}
Where createTables is my function for creating buttons dynamically.
private void createTables(int length)
{
int j = 0;
Button[] buttons = new Button[length];
for (int i = 0; i < buttons.Length; i++)
{
buttons[i] = new Button();
buttons[i].Size = new System.Drawing.Size(95, 75);
buttons[i].Name = "Button" + i.ToString();
buttons[i].Text = "Table" + (i + 1).ToString();
buttons[i].Font = new System.Drawing.Font("Comic Sans MS", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
buttons[i].Image = global::Biz_Maxx.Properties.Resources.tab;
buttons[i].TextAlign = System.Drawing.ContentAlignment.BottomCenter;
buttons[i].UseVisualStyleBackColor = true;
Point p = new Point(10 + i * 100, 10);
buttons[i].Location = p;
buttons[i].Click += new EventHandler(this.Button_Click);
Controls.Add(buttons[i]);
}
}
Here i am using the button click event to open the forms
protected void Button_Click(object sender, EventArgs e)
{
ucSales sale= new ucSales();
}
Now my actual problem is according to the buttons the ucSales forms to be opened. ie
If i click button[1], that means the first button from the dynamically created, then the ucSales form is also be like ucSale[1] , for button[2], ucSales[2] should be opened, like that for each and every buttons i dynamically created should open the ucSales forms individually .
Also want to check if the form is opened already, then only display it with the data i entered for that particular form.
My second issue is in the allocation of these buttons dynamically displayed in the form, according to the form length and width.how to display the buttons according to the form size like first row,second row.....
I am developing a restaurant software, which have so many restaurant tables in it.. according to my database restaurant tables count, the buttons should shown dynamically in the form. So that for each restaurant table having different names and different billing screens. If i click any one of the restaurant table button from the form, it should display the billing screen.
Any help appreciated
Thanks in advance