Hi, I try to develop Forms App which will count my working hours, taxes, expenses etc...
At moment Iam working on calendar. On the first form I have combobox which sends the name of month into the ReturnNumberOfDaysInCurrentMonth().

The Class returns the number of month for DateTime.DaysInMonth(int,int), which returns the quantity of days.

That's the problem. I need to create dynamically changeable set of textboxes according to quantity of days in current month. Something like:

int numbeOfDays;
TextBox tb=new TextBox();
for(int i=0; i<=numberOfDays; i++)
{
tb=(TextBox)i;
Form1.Controls.Add(tb);
}

Does anyone can advice me something? Thank you.

Start a new forms app and fill in the code below. Hope it helps you out.

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            int numberOfDays = 30;
            int Xpos = 10;
            int Ypos = 0;
            for (int i = 0; i <= numberOfDays; i++)
            {
                Ypos = 20 * (i % 6) + 3;
                if ((i % 6) == 0) Xpos += 50;
                TextBox tb = new TextBox();
                tb.Location = new Point(Xpos, Ypos);
                tb.Width = 50;
                //other properties for tb here
                this.Controls.Add(tb); //add to form
            }
        }
    }
}
commented: solved! +8

Uhm you can try this

for(int i = 0 ;i < numberOfDays; i++)
 {
    TextBox tb = new TextBox();
    tb.ID = "txt" + i;
    form1.Controls.Add(tb);
 }

regards.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.