Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HELLO
by c# - winform
I want to display a calendar in the output.
I want to have a place from the first day until the end of the year. I have 12 rows of 30. The rows and columns of the calendar are one month and the other is the number of days.
Company employees are present every 14 days and rest for 14 days.
I want to display the days of presence with a color and the days of rest in a different color in the calendar that is displayed.
How to do it

thanks

What I have tried:

i don't know what should i do

help
Posted
Updated 31-Jan-19 22:19pm

There are problems with that approach: particularly in January, March, May, July, August, October, and December which do not fit in your scheme - having 31 days in each!
So enlarge your "calendar" to a 12 by 31 matrix for starters (and actually, make it 13 by 32 so you have room for the headers: a row for 1...31 and a column for "Jan"..."Dec"
There are several ways you could do this, but the easiest is probably to create a UserControl: Right click your project in the Solution Explorer and select "Add"..."User Control...".
Call it "MyCalendar" and click the "Add" button.
You will get a blank display with some "grab handles" - use them to make it bigger.
Now go to the Properties pane, and select "Events" - it's the "lightening bolt" button.
Double click the "Paint" event and the system will create a blank event in the control for you.
Add this code:
private void MyCalendar_Paint(object sender, PaintEventArgs e)
    {
    Graphics g = e.Graphics;
    int colWidth = Width / 32;
    int rowHeight = Height / 13;
    Brush b1 = Brushes.Salmon;
    Brush b2 = Brushes.Cyan;
    bool drawB1 = true;
    for (int x = colWidth; x < Width; x += colWidth)
        {
        for (int y = rowHeight; y < Height; y += rowHeight)
            {
            g.FillRectangle(drawB1 ? b1 : b2, new Rectangle(x, y, colWidth, rowHeight));
            drawB1 = !drawB1;
            }
        }
    }
Now compile you app, then drag a MyCalendar instance from the Toolbox onto your form. See all the pretty squares? :laugh:

That won't do exactly what you want, but it's a place to start - so use that as a "template" for getting your actual calendar to work. First try to change it so it draws 14 pink squares, and 14 cyan ones. Then get it to draw the right number of days in each month. and so on. Do it in little stages, and you'll get there!
 
Share this answer
 
Comments
nv3 1-Feb-19 3:53am    
Fine advice to a newby! That's how to do it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900