示例#1
0
        internal void Draw(Graphics e)
        {
            StringFormat textFormat = new StringFormat();
            Brush        textBrush  = new SolidBrush(TextColor);
            Brush        bgBrush    = new SolidBrush(BackColor1);

            string minMonth;
            string maxMonth;
            string currentMonth;


            string month;

            textFormat.LineAlignment = StringAlignment.Center;
            switch (m_align)
            {
            case mcTextAlign.Center:
            {
                textFormat.Alignment = StringAlignment.Center;
                break;
            }

            case mcTextAlign.Left:
            {
                textFormat.Alignment = StringAlignment.Near;
                break;
            }

            case mcTextAlign.Right:
            {
                textFormat.Alignment = StringAlignment.Far;
                break;
            }
            }

            if (m_gradientMode != mcGradientMode.None)
            {
                m_calendar.DrawGradient(e, m_rect, BackColor1, BackColor2, m_gradientMode);
            }
            else
            {
                e.FillRectangle(bgBrush, m_rect);
            }


            if (m_monthSelector)
            {
                currentMonth = m_calendar.Month.SelectedMonth.Year.ToString() + "-" + m_calendar.Month.SelectedMonth.Month.ToString();

                minMonth = m_calendar.MinDate.Year.ToString() + "-" + m_calendar.MinDate.Month.ToString();
                maxMonth = m_calendar.MaxDate.Year.ToString() + "-" + m_calendar.MaxDate.Month.ToString();

                if ((minMonth == currentMonth) && (m_prevBtnState != mcButtonState.Pushed))
                {
                    m_prevBtnState = mcButtonState.Inactive;
                }
                else if (m_prevBtnState != mcButtonState.Pushed)
                {
                    m_prevBtnState = mcButtonState.Normal;
                }

                if ((maxMonth == currentMonth) && (m_nextBtnState != mcButtonState.Pushed))
                {
                    m_nextBtnState = mcButtonState.Inactive;
                }
                else if (m_nextBtnState != mcButtonState.Pushed)
                {
                    m_nextBtnState = mcButtonState.Normal;
                }
            }
            if (m_yearSelector)
            {
                currentMonth = m_calendar.Month.SelectedMonth.Year.ToString() + "-" + m_calendar.Month.SelectedMonth.Month.ToString() + "-01";

                DateTime currentDate = DateTime.Parse(currentMonth);
                int      days        = DateTime.DaysInMonth(m_calendar.MinDate.Year, m_calendar.MinDate.Month);
                DateTime minDate     = DateTime.Parse(m_calendar.MinDate.Year.ToString() + "-" + m_calendar.MinDate.Month.ToString() + "-" + days.ToString());
                days = DateTime.DaysInMonth(m_calendar.MaxDate.Year, m_calendar.MaxDate.Month);
                DateTime maxDate = DateTime.Parse(m_calendar.MaxDate.Year.ToString() + "-" + m_calendar.MaxDate.Month.ToString() + "-" + days.ToString());

                if ((DateTime.Compare(currentDate.AddYears(-1), minDate) < 0) && (m_prevYearBtnState != mcButtonState.Pushed))
                {
                    m_prevYearBtnState = mcButtonState.Inactive;
                }
                else if (m_prevYearBtnState != mcButtonState.Pushed)
                {
                    m_prevYearBtnState = mcButtonState.Normal;
                }

                if ((DateTime.Compare(currentDate.AddYears(1), maxDate) > 0) && (m_nextYearBtnState != mcButtonState.Pushed))
                {
                    m_nextYearBtnState = mcButtonState.Inactive;
                }
                else if (m_nextYearBtnState != mcButtonState.Pushed)
                {
                    m_nextYearBtnState = mcButtonState.Normal;
                }
            }


            if (m_monthSelector)
            {
                DrawButton(e, m_prevBtnState, mcHeaderButtons.PreviousMonth, m_prevBtnRect);
                DrawButton(e, m_nextBtnState, mcHeaderButtons.NextMonth, m_nextBtnRect);
            }
            if (m_yearSelector)
            {
                DrawButton(e, m_prevYearBtnState, mcHeaderButtons.PreviousYear, m_prevYearBtnRect);
                DrawButton(e, m_nextYearBtnState, mcHeaderButtons.NextYear, m_nextYearBtnRect);
            }

            month = m_calendar.m_dateTimeFormat.GetMonthName(m_calendar.Month.SelectedMonth.Month) + " " + m_calendar.Month.SelectedMonth.Year.ToString();
            if (ShowMonth)
            {
                e.DrawString(month, Font, textBrush, m_textRect, textFormat);
            }
            else
            {
                e.DrawString(m_text, Font, textBrush, m_textRect, textFormat);
            }

            textBrush.Dispose();
            bgBrush.Dispose();
        }
示例#2
0
        internal void Draw(Graphics e)
        {
            StringFormat textFormat = new StringFormat();
            Pen          linePen    = new Pen(m_borderColor, 1);
            Rectangle    weekRect   = new Rectangle();

            int   weeknr        = 0;
            Brush weekBrush     = new SolidBrush(this.BackColor1);
            Brush weekTextBrush = new SolidBrush(this.TextColor);
            int   dayHeight;

            // Draw header
            textFormat.Alignment = StringAlignment.Center;
            switch (m_align)
            {
            case mcWeeknumberAlign.Top:
            {
                textFormat.LineAlignment = StringAlignment.Near;
                break;
            }

            case mcWeeknumberAlign.Center:
            {
                textFormat.LineAlignment = StringAlignment.Center;
                break;
            }

            case mcWeeknumberAlign.Bottom:
            {
                textFormat.LineAlignment = StringAlignment.Far;
                break;
            }
            }

            if (m_gradientMode == mcGradientMode.None)
            {
                e.FillRectangle(weekBrush, m_rect);
            }
            else
            {
                m_calendar.DrawGradient(e, m_rect, m_backColor1, m_backColor2, m_gradientMode);
            }

            dayHeight = (int)m_calendar.Month.DayHeight;
            for (int i = 0; i < 6; i++)
            {
                weekRect.Y     = m_rect.Y + dayHeight * i;
                weekRect.Y    += (i + 1) * m_calendar.Month.Padding.Vertical;
                weekRect.Width = m_rect.Width;
                weekRect.X     = 0;
                if (i == 5)
                {
                    weekRect.Height = m_rect.Height - (m_calendar.Month.Padding.Vertical * 7) - (int)(dayHeight * 5) - 1;
                }
                else
                {
                    weekRect.Height = dayHeight;
                }

                weeknr = GetWeek(m_calendar.Month.m_days[i * 7].Date);

                e.DrawString(weeknr.ToString(), this.Font, weekTextBrush, weekRect, textFormat);
            }
            e.DrawLine(linePen, m_rect.Right - 1, m_rect.Top, m_rect.Right - 1, m_rect.Bottom);
            // tidy up
            weekBrush.Dispose();
            weekTextBrush.Dispose();
            linePen.Dispose();
        }
示例#3
0
        internal void Draw(Graphics e)
        {
            StringFormat textFormat = new StringFormat();
            Brush        textBrush  = new SolidBrush(TextColor);
            Brush        bgBrush    = new SolidBrush(BackColor1);

            textFormat.Alignment     = StringAlignment.Near;
            textFormat.LineAlignment = StringAlignment.Center;
            Rectangle txtRect;

            if (m_gradientMode == mcGradientMode.None)
            {
                e.FillRectangle(bgBrush, m_rect);
            }
            else
            {
                m_calendar.DrawGradient(e, m_rect, m_backColor1, m_backColor2, m_gradientMode);
            }

            textFormat.LineAlignment = StringAlignment.Center;
            // Draw header
            switch (Align)
            {
            case mcTextAlign.Left:
            {
                textFormat.Alignment = StringAlignment.Near;
                break;
            }

            case mcTextAlign.Center:
            {
                textFormat.Alignment = StringAlignment.Center;
                break;
            }

            case mcTextAlign.Right:
            {
                textFormat.Alignment = StringAlignment.Far;
                break;
            }
            }

            txtRect = new Rectangle(m_rect.Left + 2, m_rect.Top, m_rect.Width - (2 * 2), m_rect.Height);

            if (m_showToday)
            {
                if (m_format == mcTodayFormat.Short)
                {
                    e.DrawString(DateTime.Now.ToShortDateString(), Font, textBrush, txtRect, textFormat);
                }
                else
                {
                    e.DrawString(DateTime.Now.ToLongDateString(), Font, textBrush, txtRect, textFormat);
                }
            }
            else
            {
                e.DrawString(m_text, Font, textBrush, txtRect, textFormat);
            }

            // Clean up
            textBrush.Dispose();
            bgBrush.Dispose();
        }
示例#4
0
        internal void Draw(Graphics e)
        {
            Pen          linePen    = new Pen(m_borderColor, 1);
            StringFormat textFormat = new StringFormat();
            Rectangle    dayRect    = new Rectangle();
            int          dayWidth;

            string[] weekdays;

            weekdays = GetWeekDays();

            Brush headerBrush     = new SolidBrush(this.BackColor1);
            Brush headerTextBrush = new SolidBrush(this.TextColor);

            textFormat.LineAlignment = StringAlignment.Center;
            // Draw header
            switch (Align)
            {
            case mcTextAlign.Left:
            {
                textFormat.Alignment = StringAlignment.Near;
                break;
            }

            case mcTextAlign.Center:
            {
                textFormat.Alignment = StringAlignment.Center;
                break;
            }

            case mcTextAlign.Right:
            {
                textFormat.Alignment = StringAlignment.Far;
                break;
            }
            }



            if (m_gradientMode == mcGradientMode.None)
            {
                e.FillRectangle(headerBrush, 0, m_rect.Top, m_calendar.Width, m_rect.Height);
            }
            else
            {
                m_calendar.DrawGradient(e, m_rect, m_backColor1, m_backColor2, m_gradientMode);
            }

            dayWidth = (int)m_calendar.Month.DayWidth;

            for (int i = 0; i < 7; i++)
            {
                dayRect.Y      = m_rect.Y;
                dayRect.Width  = dayWidth;
                dayRect.Height = m_rect.Height;
                dayRect.X      = (dayWidth * i) + m_rect.X;
                dayRect.X     += (i + 1) * m_calendar.Month.Padding.Horizontal;
                if (i == 6)
                {
                    dayRect.Width = m_rect.Width - (int)(m_calendar.Month.Padding.Horizontal * 8) - (int)(dayWidth * 6) - 1;
                }

                e.DrawString(weekdays[i], this.Font, headerTextBrush, dayRect, textFormat);
            }
            e.DrawLine(linePen, m_rect.X, m_rect.Bottom - 1, m_rect.Right, m_rect.Bottom - 1);

            // tidy up
            headerBrush.Dispose();
            headerTextBrush.Dispose();
            linePen.Dispose();
        }
示例#5
0
		internal void Draw(Graphics e, DateItem queryInfo)
		{
											
			StringFormat dateAlign = new StringFormat();
			StringFormat textAlign = new StringFormat();
           	Font boldFont = new Font(m_month.DateFont.Name,m_month.DateFont.Size,m_month.DateFont.Style | FontStyle.Bold);
            Color bgColor1 = m_month.Colors.Days.BackColor1;
            Color bgColor2 = m_month.Colors.Days.BackColor2;
            mcGradientMode gradientMode = m_month.Colors.Days.GradientMode;
            Color textColor = m_month.Colors.Days.Text;
            Color dateColor = m_month.Colors.Days.Date;
            Brush dateBrush = new SolidBrush(dateColor);
            Brush textBrush = new SolidBrush(textColor);
            Brush bgBrush = new SolidBrush(bgColor1);
           
            string dateString;
			m_imageRect = new Rectangle(); 
			string text = "";
			bool drawDay = false;
			bool enabled = true;
            Image bgImage = null;
			
			int i = -1;

			bool boldedDate = false;
 
			DateItem[] info;
			m_dayImage = null;
	
			dateAlign = GetStringAlignment(m_month.DateAlign); 
			textAlign = GetStringAlignment(m_month.TextAlign);							
			
			if ((m_month.SelectedMonth.Month == m_date.Month) || (m_month.Calendar.ShowTrailingDates))
				drawDay = true;
			
			if ( ((m_date.DayOfWeek == DayOfWeek.Saturday) && (m_month.Colors.Weekend.Saturday)) ||
                 ((m_date.DayOfWeek == DayOfWeek.Sunday) && (m_month.Colors.Weekend.Sunday)) )
			{
			    bgColor1 = m_month.Colors.Weekend.BackColor1;
                bgColor2 = m_month.Colors.Weekend.BackColor2;
                dateColor= m_month.Colors.Weekend.Date;
				textColor= m_month.Colors.Weekend.Text;
                gradientMode = m_month.Colors.Weekend.GradientMode;  
			}			
			
			if (m_month.SelectedMonth.Month  != m_date.Month)
			{
				bgColor1 =  m_month.Colors.Trailing.BackColor1;
                bgColor2 = m_month.Colors.Trailing.BackColor2;
                gradientMode = m_month.Colors.Trailing.GradientMode;
                dateColor = m_month.Colors.Trailing.Date; 
				textColor = m_month.Colors.Trailing.Text; 
			}
				
			// Check if formatting should be applied
			if ((m_month.FormatTrailing) || (m_month.SelectedMonth.Month  == m_date.Month)) 
			{
				// check of there is formatting for this day
                if (queryInfo != null)
                {
                    info = new DateItem[1];
                    info[0] = queryInfo;
                }
                else
                    info = m_calendar.GetDateInfo(this.Date);
				if (info.Length > 0)
					i = 0;
				// go through the available dateitems
				while ((i<info.Length) && (drawDay))
				{
					if (info.Length>0)
					{
						DateItem dateInfo = info[i];
				
						if (dateInfo.BackColor1!=Color.Empty)  
							bgColor1 = dateInfo.BackColor1;
                        if (dateInfo.BackColor2 != Color.Empty)
                            bgColor2 = dateInfo.BackColor2;
						gradientMode = dateInfo.GradientMode; 
                        if (dateInfo.DateColor!=Color.Empty)  
							dateColor = dateInfo.DateColor;
						if (dateInfo.TextColor!=Color.Empty)  
							textColor = dateInfo.TextColor;
						text = dateInfo.Text; 
				
						if (dateInfo.Weekend)
						{
							bgColor1 = m_month.Colors.Weekend.BackColor1;
                            bgColor2 = m_month.Colors.Weekend.BackColor2;
                            gradientMode = m_month.Colors.Weekend.GradientMode;  
                            dateColor = m_month.Colors.Weekend.Date;
							textColor = m_month.Colors.Weekend.Text;
						}
						boldedDate = dateInfo.BoldedDate; 
						enabled = dateInfo.Enabled;
						if (!dateInfo.Enabled)
						{
							bgColor1 = m_month.Colors.Disabled.BackColor1;
                            bgColor2 = m_month.Colors.Disabled.BackColor2;
                            gradientMode = m_month.Colors.Disabled.GradientMode;     
							dateColor = m_month.Colors.Disabled.Date;
							textColor = m_month.Colors.Disabled.Text;
						}
 						
						m_dayImage = dateInfo.Image;  	
									
						if (m_dayImage!=null)
							m_imageRect = ImageRect(m_month.ImageAlign);
                        
                        bgImage = dateInfo.BackgroundImage; 
                    }

					if (m_state == mcDayState.Selected)
					{
						dateColor = m_month.Colors.Selected.Date; 
						textColor = m_month.Colors.Selected.Text;
					}
					if ((m_state == mcDayState.Focus) && (m_month.Calendar.ShowFocus))  
					{
						dateColor = m_month.Colors.Focus.Date; 
						textColor = m_month.Colors.Focus.Text;
					}
                    

                    if (bgImage != null)
                        e.DrawImage(bgImage, m_rect);
                    else
                    {
                        if (gradientMode == mcGradientMode.None)
                        {
                            if (bgColor1 != Color.Transparent)
                            {
                                bgBrush = new SolidBrush(Color.FromArgb(m_month.Transparency.Background, bgColor1));
                                e.FillRectangle(bgBrush, m_rect);
                            }
                        }
                        else
                            m_calendar.DrawGradient(e, Rectangle, bgColor1, bgColor2, gradientMode);
                    }

					
                    ControlPaint.DrawBorder(e,m_rect, m_month.Colors.Days.Border,m_month.BorderStyles.Normal);
					if (m_dayImage!=null)
					{
						if (enabled)
							e.DrawImageUnscaled(m_dayImage,m_imageRect);
						else
							ControlPaint.DrawImageDisabled(e,m_dayImage,m_imageRect.X,m_imageRect.Y,m_month.Colors.Disabled.BackColor1);   
					}
            						
					// Check if we should append month name to date
					if ((m_month.ShowMonthInDay) &&
						((m_date.AddDays(-1).Month != m_date.Month) ||
						(m_date.AddDays(1).Month != m_date.Month)))							
						dateString = m_date.Day.ToString()+" "+m_calendar.m_dateTimeFormat.GetMonthName(m_date.Month);  
					else
						dateString = m_date.Day.ToString();

                    if (dateColor != Color.Transparent)
                    {
                        dateBrush = new SolidBrush(Color.FromArgb(m_month.Transparency.Text, dateColor));
                        CharacterRange[] characterRanges = { new CharacterRange(0, dateString.Length) };
                        dateAlign.SetMeasurableCharacterRanges(characterRanges);
                        m_dateRgn = new Region[1]; 
                        // Should date be bolded ?
                        if (!boldedDate)
                        {
                            e.DrawString(dateString, m_month.DateFont, dateBrush, m_rect, dateAlign);
                            m_dateRgn = e.MeasureCharacterRanges(dateString, m_month.DateFont, m_rect, dateAlign); 
                        }
                        else
                        {
                            e.DrawString(dateString, boldFont, dateBrush, m_rect, dateAlign);
                            m_dateRgn = e.MeasureCharacterRanges(dateString, boldFont, m_rect, dateAlign);                        
                        }
					      
                    }
                    if ((text.Length > 0) && (textColor != Color.Transparent))
                    {
                        textBrush = new SolidBrush(Color.FromArgb(m_month.Transparency.Text, textColor));
                        CharacterRange[] characterRanges = { new CharacterRange(0, text.Length) };
                        textAlign.SetMeasurableCharacterRanges(characterRanges);
                        m_textRgn = new Region[1]; 
                        e.DrawString(text, m_month.TextFont, textBrush, m_rect, textAlign);
                        m_textRgn = e.MeasureCharacterRanges(text, m_month.TextFont, m_rect, textAlign); 
                    }
					i++;	
				}
			} 
								
			dateBrush.Dispose();
			bgBrush.Dispose();
			textBrush.Dispose();
			boldFont.Dispose();
			dateAlign.Dispose();
			textAlign.Dispose();
			
		}