ComponentFactory.Krypton.Toolkit.ViewLayoutMonths.DayFromPoint C# (CSharp) Method

DayFromPoint() public method

Gets the button for the day that is under the provided point.
public DayFromPoint ( Point pt, bool exact ) : DateTime?
pt Point Point to lookup.
exact bool Exact requires that the day must be with the month range.
return DateTime?
        public DateTime? DayFromPoint(Point pt, bool exact)
        {
            // Get the bottom most view element matching the point
            ViewBase view = ViewFromPoint(pt);

            // Climb view hierarchy looking for the days view
            while (view != null)
            {
                ViewDrawMonthDays month = view as ViewDrawMonthDays;
                if ((month != null) && month.ClientRectangle.Contains(pt))
                    return month.DayFromPoint(pt, exact);

                view = view.Parent;
            }

            return null;
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Mouse has moved inside the view.
        /// </summary>
        /// <param name="c">Reference to the source control instance.</param>
        /// <param name="pt">Mouse position relative to control.</param>
        public virtual void MouseMove(Control c, Point pt)
        {
            if (_mouseOver)
            {
                if (_captured)
                {
                    if (_selectionStart != DateTime.MinValue)
                    {
                        // Find the button (day entry) closest (date wise) to the point provided.
                        // So if over a blank area or over a disabled day it gives the date that
                        // would be appropriate to use as the end selection date.
                        DateTime selectEnd = _months.DayNearPoint(pt);

                        // Enforce the maximum number of days
                        DateTime selectStart = _selectionStart;
                        TimeSpan span        = new TimeSpan(_months.Calendar.MaxSelectionCount - 1, 0, 0, 0);
                        if (selectEnd > selectStart)
                        {
                            if ((selectEnd - selectStart) > span)
                            {
                                selectEnd = selectStart + span;
                            }

                            _months.FocusDay = selectEnd;
                        }
                        else if (selectEnd < selectStart)
                        {
                            if ((selectStart - selectEnd) > span)
                            {
                                selectEnd = selectStart - span;
                            }

                            // Switch around so the begin is before the end
                            DateTime temp = selectEnd;
                            selectEnd   = selectStart;
                            selectStart = temp;

                            _months.FocusDay = selectStart;
                        }

                        // Use the new seletion range
                        _months.Calendar.SetSelectionRange(selectStart, selectEnd);
                        _needPaint(_months, new NeedLayoutEventArgs(false));
                    }
                }
                else
                {
                    // Find the button (day entry) under the new mouse position
                    _months.TrackingDay = _months.DayFromPoint(pt, true);
                }
            }
        }