Ejemplo n.º 1
0
        internal void DaySelect(int i, MouseButtons button, Point mouseLocation)
        {
            bool dayEnabled = true;

            if (m_calendar.SelectionMode > mcSelectionMode.None)
            {
                m_dayInFocus = i;
                // Check if proper button is used
                if (button == m_calendar.SelectButton) 
                {

                    if (!m_days[i].ImageHitTest(mouseLocation))
                    {

                        dayEnabled = IsDateEnabled(m_days[i].Date);

                        if (((m_calendar.SelectTrailingDates) || (SelectedMonth.Month == m_days[i].Date.Month)) &&
                            ((m_calendar.MinDate <= m_days[i].Date) && (m_calendar.MaxDate >= m_days[i].Date)) && (dayEnabled))
                        {

                            // If day is already selected and number of days in selection = 1
                            // or selectionMode = MultiExtended, toggle to focus
                            if (m_days[i].State == mcDayState.Selected)
                            {
                                DayStateChangedEventArgs args = new DayStateChangedEventArgs(m_days[i].Date.ToShortDateString(), mcDayState.Selected, mcDayState.Normal);
                                if (BeforeDayDeselected != null)
                                    BeforeDayDeselected(this, args);
                                if (!args.Cancel)
                                {
                                    Remove(i);
                                }

                            }
                            else
                            {
                                DayStateChangedEventArgs args = new DayStateChangedEventArgs(m_days[i].Date.ToShortDateString(), mcDayState.Normal, mcDayState.Selected);
                                if (BeforeDaySelected != null)
                                    BeforeDaySelected(this, args);

                                if (!args.Cancel)
                                {
                                    NewSelectedDay(i);
                                }
                            }

                            m_mouseDown = true;
                            m_calendar.Invalidate();
                        }
                    }
                    else
                    {
                        if (this.ImageClick != null)
                            this.ImageClick(this, new DayClickEventArgs(m_days[i].Date.ToShortDateString(), button,
                                            mouseLocation.X - m_days[i].Rectangle.Left, mouseLocation.Y - m_days[i].Rectangle.Top,
                                            mouseLocation.X, mouseLocation.Y, m_days[i].Rectangle));
             
                    }

                }
                //either way ceate DayClick event
                if (this.DayClick != null)
                    this.DayClick(this, new DayClickEventArgs(m_days[i].Date.ToShortDateString(), button,
                                  mouseLocation.X - m_days[i].Rectangle.Left, mouseLocation.Y - m_days[i].Rectangle.Top,
                                  mouseLocation.X, mouseLocation.Y, m_days[i].Rectangle));
            }
					
        }
Ejemplo n.º 2
0
        internal void FocusMoved(int i)
        {
            bool dayEnabled = true;

            if ( (!m_mouseDown) && (!m_calendar.SelectKeyDown) )  
            {

                dayEnabled = IsDateEnabled(m_days[i].Date);

                if (((m_calendar.SelectTrailingDates) || (SelectedMonth.Month == m_days[i].Date.Month)) && (dayEnabled))
                {
                    if (m_days[i].State != mcDayState.Selected)
                        m_days[i].State = mcDayState.Focus;
                    if ((m_dayInFocus != -1) && (m_days[m_dayInFocus].State != mcDayState.Selected))
                        m_days[m_dayInFocus].State = mcDayState.Normal;

                    // raise events
                    if ((DayLostFocus != null) && (m_dayInFocus != -1))
                        DayLostFocus(this, new DayEventArgs(m_days[m_dayInFocus].Date.ToShortDateString()));
                    if (DayGotFocus != null)
                        DayGotFocus(this, new DayEventArgs(m_days[i].Date.ToShortDateString()));
                }
                else
                {
                    if ((m_dayInFocus != -1) && (m_days[m_dayInFocus].State != mcDayState.Selected))
                        m_days[m_dayInFocus].State = mcDayState.Normal;
                }

                if (m_calendar.ShowFocus)
                    m_calendar.Invalidate(m_rect);
                m_dayInFocus = i;
            }
            else if (m_calendar.SelectionMode >= mcSelectionMode.MultiSimple)
            {
                DayStateChangedEventArgs args;
                if (m_days[i].State == mcDayState.Normal)
                {
                    args = new DayStateChangedEventArgs(m_days[i].Date.ToShortDateString(), mcDayState.Normal, mcDayState.Selected);
                    if (BeforeDaySelected != null)
                        BeforeDaySelected(this, args);
                }
                else
                {
                    if (m_dayInFocus == -1)
                        m_dayInFocus = i;
                    args = new DayStateChangedEventArgs(m_days[m_dayInFocus].Date.ToShortDateString(), mcDayState.Selected, mcDayState.Normal);
                     if (BeforeDayDeselected != null)
                         BeforeDayDeselected(this, args);
                }

                m_dayInFocus = i;

                if (((m_calendar.SelectTrailingDates) || (SelectedMonth.Month == m_days[i].Date.Month)) &&
                    ((m_calendar.MinDate <= m_days[i].Date) && (m_calendar.MaxDate >= m_days[i].Date)) && (dayEnabled) && (!args.Cancel))
                {

                    if (m_newSelection)
                    {
                        NewSelectedDay(i);
                        m_newSelection = false;
                    }
                    else
                    {
                        SelectionArea area = (SelectionArea)m_selArea[m_selArea.Count - 1];
                        area.End = i;
                    }

                    m_selected = true;
                    RemoveSelection(false);
                    // loop through number of selections
                    for (int y = 0; y < m_selArea.Count; y++)
                    {
                        SelectionArea area = (SelectionArea)m_selArea[y];
                        if ((area.Begin != -1) && (area.End != -1))
                            MarkAreaAsSelected(area.Begin, area.End, y);
                    }
                    // Force repaint of calendar
                    m_calendar.Invalidate(m_rect);

                }
            }
            else
            {
                // init dagdrop
                //m_calendar.DoDragDrop(m_days[i].Date.ToString(),DragDropEffects.Copy);   
            }
        }
Ejemplo n.º 3
0
 void m_month_BeforeDaySelected(object sender, DayStateChangedEventArgs e)
 {
     if (BeforeDaySelected!=null)
         BeforeDaySelected(this, e);
        
 }