0

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.

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by jbisono
1

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
            }
        }
    }
}
Votes + Comments
solved!
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.