Mini Kabibi Habibi

Current Path : C:/Users/Public/Documents/DXperience 13.1 Demos/WinForms/CS/PhotoViewer.MDI/Controls/
Upload File :
Current File : C:/Users/Public/Documents/DXperience 13.1 Demos/WinForms/CS/PhotoViewer.MDI/Controls/DateFilter.cs

using System;
using System.Drawing;
using DevExpress.XtraEditors;

namespace PhotoViewer {
    public partial class DateFilter : XtraUserControl {
        static readonly object selectionChangedCore = new object();
        public DateFilter() {
            InitializeComponent();
        }
        protected override void OnSizeChanged(EventArgs e) {
            base.OnSizeChanged(e);
            int x = DisplayRectangle.X + (int)((DisplayRectangle.Width - calendar.Width) / 2);
            int y = DisplayRectangle.Y + (int)((DisplayRectangle.Height - calendar.Height) / 2);
            calendar.Location = new Point(x, y);
        }
        public DateTime StartDate {
            get {
                if(AllowFilter)
                    return calendar.SelectionStart;
                else return DateTime.MinValue;
            }
        }
        public DateTime EndDate {
            get {
                if(AllowFilter)
                    return calendar.SelectionEnd;
                else return DateTime.MinValue;
            }
        }
        public bool AllowFilter {
            get { return allowFilterCheck.Checked; }
        }
        protected void RaiseSelectionChanged() {
            EventHandler handler = Events[selectionChangedCore] as EventHandler;
            if(handler != null)
                handler(this, EventArgs.Empty);
        }
        public event EventHandler SelectionChanged {
            add { Events.AddHandler(selectionChangedCore, value); }
            remove { Events.RemoveHandler(selectionChangedCore, value); }
        }
        void allowFilterCheck_CheckedChanged(object sender, EventArgs e) {
            RaiseSelectionChanged();
        }
        void startDate_SelectionChanged(object sender, EventArgs e) {
            RaiseSelectionChanged();
        }
        void endDate_SelectionChanged(object sender, EventArgs e) {
            RaiseSelectionChanged();
        }
    }
}