0
Answer

Dynamic buttons

magnuswallon

magnuswallon

19y
1.7k
1
Hi all, I'm new to this forum and to c# and my first project is a simple calendar for my tablet pc. In this project I dynamicly create buttons based on current month, looks like this: private void createButtons() { int xet; int numFirstDay; DateTime myDateTime = new DateTime(activeYear,activeMonth,1); if(myDateTime.DayOfWeek==DayOfWeek.Monday) { //functions for checking witch day in week the first day is } int yet=569; int numdays = DateTime.DaysInMonth(activeYear,activeMonth); for(int i=1; i350) { yet+=20; xet=16; } p.Y=yet; p.X=xet; aButton.Location=p; aButton.Width=50; aButton.Height=20; aButton.Tag=i; aButton.Name="button"+i; aButton.Text=i.ToString(); if(i==activeDay){ aButton.BackColor = System.Drawing.SystemColors.ControlDark; } aButton.Click+=new EventHandler(aButton_Click); this.Controls.Add(aButton); xet+=50; } showDate(); } This works fine and the buttons works as planned, now to my problem. When I change month from current to upcoming or earlier I like to relocate the buttons (x and y value) and hide for example button 31 if the next month only has 30 days. But I don't know how to adress these buttons from other functions? Best Regards Magnus }