유용한 정보

[C#] MonthCalendar 요일 클릭하기

DevReff 2025. 4. 24. 00:06
728x90
728x90
SMALL


        /// <summary>
        /// 주어진 위치가 어떤 요일인지 구함
        /// </summary>
        /// <param name="xCursor">커서의 X좌표</param>
        /// <returns>
        /// [요일]
        /// - 0 : 일요일
        /// - 1 : 월요일
        /// - 2 : 화요일
        /// - 3 : 수요일
        /// - 4 : 목요일
        /// - 5 : 금요일
        /// - 6 : 토요일
        /// </returns>
        public int GetWeek(int xCursor)
        {
            int wi = (this.Width - (this.DefaultMargin.Horizontal)) / this.CalendarDimensions.Width;
            this.CellWidth = wi / 7;

            for (int k = 0; k < this.CalendarDimensions.Width; ++k)
            {
                for (int i = 0; i < 7; ++i)
                {
                    int left = (this.CellWidth * i) + wi * k;
                    int right = (this.CellWidth * (i + 1)) + wi * k;
                    if (left < xCursor && xCursor < right)
                        return i;
                }
            }

            return -1;
        }

반응형

예제)

WindowsFormsApp2.zip
0.06MB

 

 

 

728x90
728x90
LIST