예제 #1
0
        protected virtual void OnValueChanged(PersianDate curDate, PersianDate oldDate)
        {
            if (ValueChanged != null)
            {
                ValueChanged(this, new PersianMonthCalendarEventArgs {
                    CurrentValue = curDate, OldValue = oldDate
                });
            }


            //if change month raise change arrangment
            if (
                selectedCell == null ||
                (curDate.Month != oldDate.Month) ||
                (curDate.Year != oldDate.Year) ||
                (curDate == PersianDate.Now)
                )
            {
                FillCells(curDate);     //change arrangment

                bodyPanel.Invalidate(); //Raise paint method
            }
            else
            {
                DrawChangeDayInMonth(null, this.oldSelectedCell, curDate);
            }
        }
예제 #2
0
        private void DrawChangeDayInMonth(Graphics gr, CellInfo oldSelected, PersianDate curDate)
        {
            if (gr == null)
            {
                gr = Graphics.FromHwnd(bodyPanel.Handle);
            }

            //SmoothingMode =antialias
            gr.SmoothingMode = SmoothingMode.AntiAlias;

            SizeF textsize = gr.MeasureString(selectedCell.Value.Day.ToString("00"), this.Font);

            gr.FillRectangle(brush, selectedCell.Rectangle);
            gr.DrawString(selectedCell.Value.Day.ToString("00"), this.Font, Brushes.White, selectedCell.Rectangle, sf);

            if (oldSelected == null)
            {
                return;
            }
            textsize = gr.MeasureString(oldSelected.Value.Day.ToString("00"), this.Font);
            gr.FillRectangle(Brushes.White, oldSelected.Rectangle);
            if (!((PersianDate)todayLink.Tag == oldSelected.Value || (IsMarkDate(oldSelected.Value))))
            {
                gr.DrawRectangle(whitePen, oldSelected.Rectangle);
            }

            gr.DrawString(oldSelected.Value.Day.ToString("00"), this.Font, Brushes.Black, oldSelected.Rectangle, sf);
            DrawToday(gr, curDate);
            gr.Dispose();
        }
예제 #3
0
 private void headerPanel_Click(object sender, EventArgs e)
 {
     if (yearNumericUpDown.Visible)
     {
         yearNumericUpDown.Visible = false;
         try
         {
             var p = new PersianDate(((int)yearNumericUpDown.Value), persianValue.Month, persianValue.Day, persianValue.Hour, persianValue.Minute, 0);
             this.Value = p;
         }
         catch (ArgumentException) { }
     }
 }
예제 #4
0
 private void DrawToday(Graphics gr, PersianDate curDate)
 {
     if (this.showToday)
     {
         string     date      = curDate.ToString("DD dd NM yyyy");
         SizeF      textSize  = gr.MeasureString(date, this.Font);
         RectangleF rect      = new RectangleF(bodyPanel.Width - (textSize.Width + 8), bodyPanel.Height - textSize.Height - 7, textSize.Width + 5, textSize.Height);
         RectangleF emptyRect = rect;
         emptyRect.X     -= 150;
         emptyRect.Width += 150;
         gr.FillRectangle(Brushes.White, emptyRect);
         gr.DrawString(date, this.Font, brush, rect, sf);
     }
 }
예제 #5
0
        // Summary:
        //     Initializes a new instance of the H128Controls.PersianMonthCalendar class.
        public PersianMonthCalendar()
        {
            InitializeComponent();

            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            this.SetStyle(ControlStyles.Selectable, true);

            sf.Alignment   = StringAlignment.Center;
            persianValue   = PersianDate.Now;
            todayLink.Text = persianValue.ToString("امروز: DD dd NM yyyy");
            todayLink.Tag  = persianValue;

            markDateList = new List <PersianDate>();

            FillCells(persianValue);
        }
 protected virtual void OnValueChanged(PersianDate curDate, PersianDate oldDate)
 {
     if (curDate == oldDate)
     {
         return;
     }
     if (!PersianDate.ValidDate(curDate))
     {
         curDate = oldDate;
     }
     //UpdateRectangle(curDate);
     DrawDate(this.Graphic);
     if (ValueChanged != null)
     {
         ValueChanged(this, new PersianMonthCalendarEventArgs {
             CurrentValue = curDate, OldValue = oldDate
         });
     }
 }
예제 #7
0
        private void FillCells(PersianDate date)
        {
            PersianDate tempDate = PersianDate.MinValue;

            if (date == PersianDate.MinValue)
            {
                return;
            }

            if (markDateList.Count > 0 && !(isMarkListSorted))
            {
                markDateList.Sort();
                isMarkListSorted = true;
            }
            cells = new CellInfo[42];
            int i, j, iCounter = 0;
            int iWidth = 43, iHeight = 13;
            int iLeft = bodyPanel.Width, iTop = 20;

            //PersianDate tempDate = date.AddDays(date.GetDaysInMonth()-date.Day);
            tempDate = date.GetLastSaturday();

            for (i = 0; i < 6; i++)
            {
                iLeft = bodyPanel.Width;
                for (j = 0; j < 7; j++)
                {
                    iLeft -= 46;

                    cells[iCounter]           = new CellInfo();
                    cells[iCounter].Value     = tempDate;
                    cells[iCounter].Rectangle = new Rectangle(iLeft, iTop, iWidth, iHeight);

                    iCounter++;


                    tempDate = tempDate.AddDays(1);
                }
                iTop += 17;
            }
        }
        private void SetDateTimeByKeyboardBuffer()
        {
            if (_digit.Length > 0)
            {
                int digit = Convert.ToInt32(_digit);
                _digit = "";
                //PersianDate date = new PersianDate();
                //date.Assign(persianValue);
                switch (selectedCommand)
                {
                case DatePartTypes.Day:
                    Value = new PersianDate(persianValue.Year, persianValue.Month, digit, persianValue.Hour, persianValue.Minute, persianValue.Second);;
                    break;

                case DatePartTypes.Month:
                    Value = new PersianDate(persianValue.Year, digit, persianValue.Day, persianValue.Hour, persianValue.Minute, persianValue.Second);;
                    break;

                case DatePartTypes.Year:
                    if (digit < 100)
                    {
                        digit += 1300;
                    }
                    Value = new PersianDate(digit, persianValue.Month, persianValue.Day, persianValue.Hour, persianValue.Minute, persianValue.Second);;
                    break;

                case DatePartTypes.Hour:
                    Value = new PersianDate(persianValue.Year, persianValue.Month, persianValue.Day, digit, persianValue.Minute, persianValue.Second);;
                    break;

                case DatePartTypes.Minute:
                    Value = new PersianDate(persianValue.Year, persianValue.Month, persianValue.Day, persianValue.Hour, digit, persianValue.Second);;
                    break;
                }
                //OnValueChanged(Value, date);
            }
        }
예제 #9
0
        private bool IsMarkDate(PersianDate date)
        {
            int iIndex = markDateList.BinarySearch(date);

            return(iIndex > -1);
        }
        private void UpdateRectangle(PersianDate curDate)
        {
            if (curDate == null)
            {
                return;
            }

            this.sizeChanging = true;
            Graphics gr = this.Graphic;

            if (gr == null)
            {
                return;
            }

            SizeF textSize = gr.MeasureString(curDate.Year.ToString("0000"), font, 0, sf);

            this.Height = ((int)textSize.Height) + 4;
            float fY = ((((float)this.Height) / 2) - (textSize.Height / 2));

            //rectYear = new RectangleF(0, (int)((this.Height / 2) - (textSize.Height / 2)), textSize.Width, textSize.Height);
            rectYear = new RectangleF(2, fY, textSize.Width, textSize.Height);

            textSize = gr.MeasureString("/", font, 0, sf);
            rectSep1 = new RectangleF(rectYear.Right - (textSize.Width / 3.5F) + 2, fY, textSize.Width, textSize.Height);

            textSize  = gr.MeasureString(curDate.Month.ToString("00"), font, 0, sf);
            rectMonth = new RectangleF(rectSep1.Right - rectSep1.Width / 3.5F, fY, textSize.Width, textSize.Height);


            rectSep2 = new RectangleF(rectMonth.Right - rectSep1.Width / 4F + 2, fY, rectSep1.Width, rectSep1.Height);

            textSize = gr.MeasureString(curDate.Day.ToString("00"), font, 0, sf);
            rectDay  = new RectangleF(rectSep2.Right - rectSep1.Width / 3.7F, fY, textSize.Width, textSize.Height);

            textSize = gr.MeasureString(curDate.Hour.ToString("00"), font, 0, sf);
            rectHour = new RectangleF(rectDay.Right + gr.MeasureString("  ", font).Width, fY, textSize.Width, textSize.Height);

            textSize    = gr.MeasureString(":", font, 0, sf);
            rectSepHour = new RectangleF(rectHour.Right - textSize.Width / 3.5F, fY, textSize.Width, textSize.Height);

            textSize   = gr.MeasureString(curDate.Minute.ToString("00"), font, 0, sf);
            rectMinute = new RectangleF(rectSepHour.Right - rectSepHour.Width / 3.5F, fY, textSize.Width, textSize.Height);



            this.rectFillYear         = this.rectYear;
            this.rectFillYear.Height -= 1;

            this.rectFillMonth         = this.rectMonth;
            this.rectFillMonth.Height -= 1;

            this.rectFillDay         = this.rectDay;
            this.rectFillDay.Height -= 1;

            this.rectFillHour         = this.rectHour;
            this.rectFillHour.Height -= 1;

            this.rectFillMinute = this.rectMinute;
            //this.rectFillMinute.Width += 6;
            this.rectFillMinute.Height -= 1;


            rectComboButton = new Rectangle(this.Width - 21, (int)rectYear.Y, 20, this.Height - 1);

            //  gr.Dispose();
            this.sizeChanging = false;
        }