Hey,
I am working on a project where i need to be able to create an unspecified number of controls (Calendars) on a form and dynamically size them based on the space on the form. I have most of this working however i am having trouble putting the the controls into an array... I have some sample code that will create an additional control without problem so i just need a little help tweaking it
(Please note i come from an Access/VBA background so please don't judge for not knowing some of the C# Nuances!)
I am working on a project where i need to be able to create an unspecified number of controls (Calendars) on a form and dynamically size them based on the space on the form. I have most of this working however i am having trouble putting the the controls into an array... I have some sample code that will create an additional control without problem so i just need a little help tweaking it
(Please note i come from an Access/VBA background so please don't judge for not knowing some of the C# Nuances!)
C#:
int formsize = this.Width;
int leftSpot = 0;
calwidth = this.calendar1.Size.Width;
leftmargin = formsize - calwidth;
//resize existing calendar
numCals = numCals + 1;
calwidth = (calwidth / numCals) - 5;
this.calendar1.Width = calwidth;
//Create new calendar control
Calendar Cal2 = new Calendar();
Cal2.Name = "calendar" + numCals.ToString();
Cal2.Width = calwidth;
Cal2.Height = this.calendar1.Height;
Cal2.Top = calendar1.Top;
calwidth = (this.Width - this.monthView1.Width) - (5 * numCals) / numCals;
calwidth = calwidth - (5 * numCals);
calwidth = calwidth / numCals;
Cal2.Left = this.monthView1.Width + (calwidth * (numCals -1));
Cal2.Anchor = (AnchorStyles.Bottom | AnchorStyles.Top );
//Place control on form
Controls.Add(Cal2);
//relocate other calendars
ReSizeCalendars();