PART 1 | How To Create a Calendar in C#.NET Windows Form using UserControl
HTML-код
- Опубликовано: 11 окт 2021
- Thanks for watching. If you liked this video, make sure to subscribe for more
PART 2
• Part 2 | How to Create...
PART 3
• Part 3 | How to Create... - Наука
Hello guys, please subscribe to my channel if my video help you. I will upload more tutorials and ideas.
What did you do at 9:20 ...what did you press to do thing you did?
@@Guide4Ever hello sir, i only deleted those panel i added inside flowlayout. i only added those panels to get thr right size of the usercontrol.
I will try to add commentary or text to my upcoming tutorials.
@@coding_ideas Thank you! :)
How to movie next year??
@@PradeepKumar-cq1dz What do you mean? Movie?
so instead of copying and pasting that entire method's code, you can just declare static variables at the top of the class for the form so that they are accessible like so:
static DateTime currentDT = DateTime.Now;
static int currentYear = currentDT.Year;
static int currentMonth = currentDT.Month;
and for the next button all you have to do is write these three lines:
("displayDays" is my method name for creating the user control by the way (where the two for loops are).)
dayContainer.Controls.Clear();
currentMonth += 1;
displayDays();
and finally for the previous button you can do:
dayContainer.Controls.Clear();
currentMonth -= 1;
displayDays();
then if you want the year to update after december just set a condition in the button click method for either button where if the current month is equal to 1 or 12 you can increment or decrement the year by 1.
private void DisplayDays()
{
int days = DateTime.DaysInMonth(currentYear, currentMonth);
DateTime startOfMonth = new DateTime(currentYear, currentMonth, 1);
int dayOfWeek = ((int)startOfMonth.DayOfWeek + 6) % 7; //monday start
for (int i = 0; i < dayOfWeek; i++)
daysContainer.Controls.Add(new dayBlock());
for (int i = 1; i
THANK YOU SO MUCH, I'VE BEEN LOOKING FOR SOMETHING LIKE THIS FOR A LONG TIME.!!
Thank you for sharing the knowledge. keep up the good work!
Thank you very much for this video. I have been trying to find a way to create a calendar such as this for a very long time. Please keep up the good work.
You're welcome ☺️. And thank you for watching my video.
Thank you!!! So informative.
Good video! Helped me a lot! But how did you get the individual dates into separate boxes?
You can use this for error.
(button_click events)
(decrease)
if (month==1)
{
month = 13;
year--;
}
month--;
and
(increase)
if (month==12)
{
month = 0;
year++;
}
month++;
At some point in the program you want the 0 or 13th month name and we get the error.
aga merhaba bu kodu nereye yazıcaz tam olarak? bir de yazınca bu sefer ayları 2şer 2şer atlamaya başlıyo bunun çözümünü biliyo musun
@@felixandro1512 2 tane butonun var birisi ay'ı artırıyor diğeri azaltıyor. Ay değerleri de sayı olarak tutuluyor sen o sayının hangi aya denk geldiğini isim olarak alıyosun. Eğer bu belirttiğim kodu yazmazsan ay değeri 1 iken yani Ocak ayında sen Ay değerini azalttığında 0. ay diye bişe olamayacağı için program hata verir. Veya aynı şekilde tam 12. ayda iken sen Ay değerini artırırsan 13. ay yine hata verir. Bu kodu 2'ye bölüp birini ayı artıran butonun click olayına diğerini ay'ı azaltan butonun click olayının en üstüne yazarsan bu sorun çözülür. 2şer 2şer artmasının sebebi month-- veya month++ diye artıran bi kod daha vardır. Onu silmen gerekir benim yazdığım kod zaten kendisi artırıp azaltıyor. (decrase) yazan kod kısmı ay'ı azaltan butona (increase) yazan kod ay'ı artıran butona yazılacak.
@@albayrak96 hocam onu hallettim teşekkürler. Şuan uygulama tamam bir sıkıntı yaşıyorum onu bi söylesem. Sql Server kullanıyorum. Takvime kaydettiğim notlar takvimin üzerinde kalmıyor. Ve sqlde en son ne kayıtlıysa onu yazıyor tüm tıkladığım günlere. Başka bir şey yazdığımda sqle kaydediyor ancak takvimin üzerinde o notu göstermiyor. Hata nerde olabilir çözüm nedir sizce
@@felixandro1512 Bunu böyle cevaplamak biraz zor yazdığın kodu ve sql tablonu görmek gerekiyor belki sql'e veri gönderirken hatalı gönderiyo olabilirsin veya sorguda hata olabilir. Sql tablonuzda tarih verisini date olarak mı tutuyosunuz?
@@albayrak96 datetime olarak tutuyorum
THANK U!! u safed me!!!! it didn't work out for me at the beginning, but I removed +1 from the line, i found a my mistake, and everything came out! good luck to you! your videos are very good, I hope you will continue to do video lessons
what mistake did you have? Because I have troubles at the beginning :(
Great Tutorial!! Thank you bro!
Thank you made my day
Excelent!!, one question : How can I do to record appointments but for the entire series of a specific day?
Thank you so much po! God bless. 🥰
You are welcome☺️. God Bless sa capstone niyo. Laban lang :) .
@@coding_ideas Thank youuuu po talagaa.
when I open the code, instead of showing just a short section with Form1_Load, several sections appear, one for each panel I created, referring to the day of the week, why does this happen?
for anyone wondering if u want the calendar to go to next and previous years u can add this below the month++ and month--
month--;
if (month == 0)
{
month = 12;
year--;
}
month++;
if (month == 13)
{
month = 1;
year++;
}
Hi! Very great video and helped me a lot with a project that I did. I was wondering if you could tell me or point me in the right direction on how to have a calendar for only week by week, instead of the whole month.
Hello, Thanks for watching. Im glad that it helped you. I havnt figure it out yet on how to create a calendar by week, if i have free time i can try to make one :). Just try to play with usercontrol class maybe it will help
sir how to fix this error for the UserBlankControl it shows "System ArgumentExceptions:Top-level control cannot be added to a control
thx for the video mate!
I have a question. I transfer this storage device to WPF, and when I open the full window, the grid gets lost and there is a discrepancy between the days of the week. How can I fix this?
Good morning, very good tutorial, my question: How can you fill in the blank controls with the days before, greetings from Argentina.
Great tutorial, not wanting to abuse it, but I would like to color the current day in the calendar and Sundays in red.
hello, Sorry for the delayed response.
declare a static variable for your month and year in your
main form, and assign a value.
example :
staticMonth = currentMonth;
staticYear = currentYear;
and in your UserControl Days.
create current date variable
example :
currentDate = MainForm.staticMonth + "/" + lbday.text + "/" + MainForm.staticYear;
and compare the currentDate and dateToday. if both are equal u can customize UserControl.
In this follow-up is a lot of work, thank you very much for your feedback.
@@coding_ideas
I'm sorry. Please explain in more detail.
It's giving error on writing daycontainer.Controls.Add(ucblank)
Hello, at 9:21. What's going on, you're doing a cut?
i have the same question
Hello. Please help me. How can I display the selected date on the FlowLayoutPanel form?❤❤❤
Gracias me salvaste el día
You're welcome :), please subscribe to my channel :)
How come I cant find WinFormsApp on my new project templates?
For me the 31st date of the month is not show only till 30th
Any solution.
У вас отсчет дней недели идёт с воскресенья, получаетсч с 1 дня по 6, а у нас 7 дней недели, начиная с понедельника, как быть?
I have a problem the last day of the month is not shown.
The months that end on a Saturday cause an issue. Next month starts on a Monday, instead of a Sunday. Any suggestions?
if anyone has the same issue, add the following before the daysOfTheWeek loop:
if (daysOfTheWeek == 0)
{
daysOfTheWeek = 7;
}
@@berbafan67 Thank You!
Hi! Do you have uploaded code example githib or gitlab?
Hello, Thanks for watching. I dont upload my tutorials on github yet because i need to reach youtube watch hours for now :) . I hope u understand.
hy...how can this be made Responsive ?
I'm really confused about how you made "DateTimeFormatInfo" work.
I can’t figure out an issue I have come across. When you go to next year, if the 1st of January falls on a Sunday it adds it on as Monday, but from February onwards the dates are correct. how can I resolve this issue?
u need to add
if (daysOfTheWeek == 0)
{
daysOfTheWeek = 7;
}
before the loop to add black usercontrols
I am getting everything right! Except that it always starts from the top left corner (My Calendar starts with Monday), no matter which month it is!
Maybe you have a hint!
Hello, Have you added a blankUserControl and create a loop? And if u start your week with monday, try to remove the (+1) i added at thr dayofthrweek.
Good luck.
@@coding_ideas it works now, thanks for your support!
At 11:23 : Somehow it doesn't show the User Control stuff, but just the plain form with the names of the days of the week. Is there a way to fix it?
have a same problem, do you know how to fix it?
@@iredderpvp7094 Sadly no, it just doesn't work for me😢
Hi, I ran into this issue as well on my end and was wondering why this was happening. Turns out the Form1_Load method (where displayDays is being called) was not bound to the actual form... hence a blank form is displayed with no user controls, so displayDays is also never called. To fix this, you need to bind the form to the Form1_Load method under the Events section under the form's properties in the "Load" attribute. Then user controls will be displayed!
buenas me parecio muy ineteranse tu calendario y si deseo hacer un ingreso multiple de varioa dias
Hello, great video, but i have a problem. For some reason my version doesnt show 31st(im doing this in december)
Do you know why?
for int i = 0
you put > instead of => i did the same
how can i do this with a week view with time on the y axis, like a timespan which events get adjusted to
I dont know how to do it yet. I will try if i have free time
@@coding_ideas thanks. Keep up the Great work
I dont understand line 35 (int = dayOfTheweek)
Why the daycontainer is not working on me
Add source code, please...
At 10:50 you type in daycontainer.Controls.etc.etc. Yet, I have followed your build to a T and and DayContainer doesn't exist. You have mentioned in only comments that it's in FlowLayoutPanel yet it isn't. I have built and rebuilt this calendar following your design. Is there a unique template that houses this Daycontainer. Please be a detailed as you can and say where/how exactly we can get daycontainer to work.
I apologize for the confusion. 'Daycontainer' is the name of my flowlayout. If 'daycontainer' does not exist in your project, please check the name of your flowlayout.
Hello, your video is very nice, but I cannot move on to the next year, I am getting an error, can you help me?
Error message!
System.ArgumentOutOfRangeException: 'Year, Month and Day parameters create a DateTime value that cannot be represented.'
in btnprevious_Click use should add:
if (month > 12)
{
month = 1;
year--;
}
and btnnext_Click will change into year++
What he did exactly ruclips.net/video/tY8_GE6NRYA/видео.html when he marked all those containers?
what you press in 9:19?
delete :)
Some commentary would really be useful, I hope you consider this. Well done on tutorial nonetheless.
Thank you :)
@@coding_ideas The subjects of your videos are excellent. I would live to learn this stuff from you. But, that requires that you actually explain what you are doing and why. Thare are already way too many "music"-tutorialls on RUclips, I just close and search for the reals ones with voice commentary. Please consider re-doing them with voice commentary instead.
Hi! good video. But i had a question, putting the:
for (int i = 1; i < dayoftheweek ; i++){
...
}
Don't show the panel, i dont know why, can you help me plis??
*Im suscribed
same here. Did you solved it?
@@felixandro1512 no,
I posted the question at stackoverflow, but nodobody answer me
Hello, how did you get to the next year? I get an error after december 2021 cause its says its out of range, very usefull video
Hello, you can create a condition if it reach december 2021, increment the year :) if month > 12(month)
increment year.
@@coding_ideas it worked, thank you! Great videos :D
@@samanthamilanezmadrigal4304 Can you help me with this problem and share where and what did you write? Thank you so much
@@romualdas9653 he added the code in one of the comments below, you have to create a condition so the year increases or decreases depending on the month. Here's the code to increase the year
year = DateTime.Now.Year;
if (month != 12)
{
month++;
}
else {
month = 1;
year++;
}
@@samanthamilanezmadrigal4304 I am sorry for interupting, I am pretty new in this and I cant find place where to put it..
hi need help at 11:20 temporary text does not show for me even if I copied the whole code please help!
x2
Removing and adding UserControls every time is bad for performance. In my calendar implementation (on the channel), all days are redrawn. This takes away the annoying flickering . 😋
can you share the code
@@baynaamn on my channel
@Coding Ideas cant access the daycontainer function. How can we access that?
I apologize for the late reply. Daycontainer is the name of the flowlayout panel.
What are you doing at 9.20 timing in daycontainer
After December and January I am facing error can you help
Can somebody explain me what is he doing here 9:14
at 9:22 what did you do did you just delete everything or what i cant understand
Yes, he had deleted.
11:00 how did you create daycontainer?
it is a flowlayout control
Thank you, can you please put a link so we can download the project, thanks!
the whole project
Your coding type is terrible, but for beginner its clearly to understand. but instead of using the same code block 3 times and have 2 exact same events for the buttons, i would create one Event for all buttons and let them access dynamically.
private void ForwardOrBackward(object sender, EventArgs e)
{
Button button = sender as Button;
switch (button.Name)
{
case "BtnNext":
month++;
if (month == 13)
{
year++;
month = 1;
}
break;
case "BtnBack":
month--;
if (month == 0)
{
year--;
month = 12;
}
break;
}
daycontainer.Controls.Clear();
DisplayDays();
}
private void Form1_Load(object sender, EventArgs e)
{
now = DateTime.Now;
month = now.Month;
year = now.Year;
DisplayDays();
}
void DisplayDays()
{
DateTime startOfTheMonth = new DateTime(year, month, 1);
LbMonth.Text = startOfTheMonth.ToString("MMMM").ToUpper() + " | " + year;
int days = DateTime.DaysInMonth(year, month);
int dayOfTheWeek = Convert.ToInt32(startOfTheMonth.DayOfWeek.ToString("d")) + 6;
if (dayOfTheWeek >= 7)
dayOfTheWeek -= 7;
for (int i = 1; i < dayOfTheWeek; i++)
{
UserControlBlank ucBlank = new UserControlBlank();
daycontainer.Controls.Add(ucBlank);
}
for (int i = 1; i
Hello Steven, Thank you for the comment . You're right, it seems terrible way of coding but the target of my videos is beginners. so that they can create beautiful applications with a simple and easy to understand method, and it is up to them to improve the method of coding. have a nice day and happy coding :)
Hello, really good tutorial but how can the previous button go back to the previous year?
Decrement the year
@@coding_ideas from what to what?
@@tomfarley6352 create a condition when u clicked previous on january. Decrement the year and set the month to 12. If(month
@@coding_ideas I will try this, thank you for replying! 👍🏻
@@tomfarley6352 if you did it can you share the code with me?
what did u do in 9:17 ?
I just removed the panel i added :) . I only put those panels to get the right size of the usercontrol :) .
@@coding_ideas The thing is that the loop is not showing the usercontrolblank into the calendar.
check ur loop if u add the usercontrolblank controls to ur container. ucdayscontainer.controls.add(usercontrolblank).
I do not understand where daycontainer came from in 11:55
It is the name of the panel he created at the start
what did you do in 9:15?
I simply select and delete all panels inside the main panel.
11:27 i don't know but in my laptop it is not show userControlBlank ?
what do u mean by it does not show usercontrolblank ?
how did you solve this problem?
Have the same problem right here, did you figure out a way to fix it?
08:51 are you delete all ? or something
I apologize for the incomplete instruction. Yes, I deleted everything. I just placed it there as a guide to determine the proper size of the user control days
Hello how to do that 9:16 ?
I simply select all the panels within the main panel and delete all of them.
at 9:20, what did you do?
I want to know too
How to movie next year??
...
month++;
if (month == 12)
{
year++;
month = 1;
}
DateTime StartOfTheMonth = new DateTime(year, month, 1);
...
@@user-mo5wt4ue2r it helped but now i can't switch to December. Any helps?
@@felixandro1512 can you write the code?
@@user-mo5wt4ue2r i solved it thx anyway
@@user-mo5wt4ue2r
Hello, there is still an error
' int days = DateTime.DaysInMonth(year, month); ' error=>System.ArgumentOutOfRangeException: 'Year, Month, and Day parameters describe an un-representable DateTime.'
. How to solve this?
what can i do if my computor dont know what is daycontainer?
Daycontainer is a flowlayout control
@@coding_ideas what is a flowlayout control?
@@user-oj7nt2tp1g You can use the flowlayoutpanel from the tool box and drop it in the design
lol. ugh.