J'ai créé un controle calendrier à l'aide de GDI.
Ce calendrier est pour le moment quasi similaire au calendrier standard monthcalendar. Chaque jours de mon calendrier correspond à un rectangle. Je souhaiterais savoir quelle est la meilleure facon de faire pour détecter un clic sur tel ou tel jours. Je suppose qu'a un moment ou a un autre je devrais utliser la Rectangle.Contains() mais après je ne sais pas trop comment m'y prendre donc si vous avez des pistes pour éviter de me lancer dans un chemin boueux...merci

La fonction de dessin de mon calendrier :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
 
private void DrawCalendar(DateTime date)
        {
            Graphics g = this.CreateGraphics();
            int lineHeight = (int)this.Height / 9;
            int colWidth = (int)this.Width / 7;
            int xPos = 0, yPos = 0;
            DateTime[] firstWeekOfMonth;
 
            Rectangle rHeader = new Rectangle(xPos, yPos, Width, lineHeight);
 
            Button btnPrevious = new Button();
            Button btnNext = new Button();
 
            btnPrevious.Location = new Point(xPos, yPos);
            btnPrevious.Size = new Size(lineHeight, lineHeight);
            btnPrevious.Text = "<<";
            btnPrevious.Click += new EventHandler(btnPrevious_Click);
            this.Controls.Add(btnPrevious);
 
 
            btnNext.Location = new Point(Width - lineHeight, yPos);
            btnNext.Size = new Size(lineHeight, lineHeight);
            btnNext.Text = ">>";
            btnNext.Click += new EventHandler(btnNext_Click);
            this.Controls.Add(btnNext);
 
            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            g.DrawString(culture.DateTimeFormat.GetMonthName(date.Month).ToString() +  date.ToString(" yyyy"), headerFont, new SolidBrush(headerColor), rHeader, sf);
            yPos += lineHeight;
 
            for (int i = 0; i <= 6; i++)
            {
                DayOfWeek day = FRIntToDayOfWeek(i);
                g.DrawRectangle(new Pen(gridBorderColor), xPos, yPos, colWidth, lineHeight);
                g.DrawString((culture.DateTimeFormat.GetDayName(day)).ToString().Substring(0, 3), dayNumberFont, new SolidBrush(dayNumberColor), new Rectangle(xPos, yPos, colWidth, lineHeight));
                xPos += colWidth;              
            }
 
            xPos = 0;
            yPos += lineHeight;
 
            firstWeekOfMonth = MFFTools.GetTabDaysOfWeek(MFFTools.GetFirstDayOfMonth(date));
 
            for (int i = 1; i <= 6; i++)
            {
                for (int j = 0; j <= 6; j++)
                {
                    g.DrawRectangle(new Pen(gridBorderColor), xPos, yPos, colWidth, lineHeight);
                    g.DrawString(firstWeekOfMonth[j].Day.ToString(), dayNumberFont, new SolidBrush(dayNumberColor), new Rectangle(xPos, yPos, colWidth, lineHeight));
                    xPos += colWidth;
                }
                if (xPos + colWidth > Width)
                {
                    yPos += lineHeight;
                    xPos = 0;
                }
                for (int j = 0; j <= firstWeekOfMonth.Length - 1; j++)
                {
                    firstWeekOfMonth[j] = firstWeekOfMonth[j].AddDays(7);
                }
            }
            g.DrawString(DateTime.Now.ToString("dd ") + culture.DateTimeFormat.GetMonthName(DateTime.Now.Month) + DateTime.Now.ToString(" yyyy"), footerFont, new SolidBrush(footerColor), new Rectangle(xPos, yPos, Width, lineHeight));        
        }