private void maskedTextBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == '/' || e.KeyChar == '-') { string txt = defaultMaskedTextBox.Text; int start = defaultMaskedTextBox.SelectionStart; start = start / 3; switch (start) { case 0: string num = txt.Substring(0, 2).Trim(defaultMaskedTextBox.PromptChar); if (num.Length == 0) { FarsiCalendarComponent.FarsiDate fdate = new FarsiCalendarComponent.FarsiDate(); num = fdate.TwoDigitYear.ToString("D2"); } else if (num.Length == 1) { num = "0" + num; } txt = num + txt.Substring(2); break; case 1: num = txt.Substring(3, 2).Trim(defaultMaskedTextBox.PromptChar); if (num.Length == 0) { num = "01"; } else if (num.Length == 1) { num = "0" + num; } txt = txt.Substring(0, 3) + num + txt.Substring(5); break; case 2: num = txt.Substring(6, 2).Trim(defaultMaskedTextBox.PromptChar); if (num.Length == 0) { num = "01"; } else if (num.Length == 1) { num = "0" + num; } txt = txt.Substring(0, 6) + num; break; } defaultMaskedTextBox.Text = txt; defaultMaskedTextBox.SelectionStart = (start * 3) + 3; e.Handled = true; } // User changed the date value OnValueChangedByUser(); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); FarsiCalendarComponent.FarsiDate farsiDate1 = new FarsiCalendarComponent.FarsiDate(); this.farsiCalendarControl = new FarsiCalendarComponent.FarsiCalendarControl(); this.SuspendLayout(); // // farsiCalendarControl // this.farsiCalendarControl.BackColor = System.Drawing.Color.White; this.farsiCalendarControl.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); this.farsiCalendarControl.DaysBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(204)))), ((int)(((byte)(199)))), ((int)(((byte)(186))))); this.farsiCalendarControl.Dock = System.Windows.Forms.DockStyle.Fill; this.farsiCalendarControl.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(178))); this.farsiCalendarControl.GridColor = System.Drawing.Color.FromArgb(((int)(((byte)(236)))), ((int)(((byte)(233)))), ((int)(((byte)(216))))); this.farsiCalendarControl.HeaderBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(50)))), ((int)(((byte)(50)))), ((int)(((byte)(240))))); this.farsiCalendarControl.HorizontalGridLines = true; this.farsiCalendarControl.Location = new System.Drawing.Point(0, 0); this.farsiCalendarControl.Name = "farsiCalendarControl"; this.farsiCalendarControl.NumbersColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); this.farsiCalendarControl.SelectedBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(170)))), ((int)(((byte)(170)))), ((int)(((byte)(250))))); this.farsiCalendarControl.SelectedFarsiValue = farsiDate1; this.farsiCalendarControl.SelectedNumberColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(250))))); this.farsiCalendarControl.ShowSmallDayName = true; this.farsiCalendarControl.ShowToday = true; this.farsiCalendarControl.Size = new System.Drawing.Size(197, 200); this.farsiCalendarControl.TabIndex = 0; this.farsiCalendarControl.Text = "farsiCalendarControl1"; this.farsiCalendarControl.TodayBorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(250)))), ((int)(((byte)(200)))), ((int)(((byte)(150))))); this.farsiCalendarControl.TodayNumberColor = System.Drawing.Color.FromArgb(((int)(((byte)(250)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); this.farsiCalendarControl.VerticalGridLines = true; // // CalendarForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(197, 200); this.ControlBox = false; this.Controls.Add(this.farsiCalendarControl); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Name = "CalendarForm"; this.ShowIcon = false; this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; this.Text = "CalendarForm"; this.TopMost = true; this.ResumeLayout(false); }
protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { Rectangle cellRect = new Rectangle(cellBounds.Location, new Size(cellBounds.Width - 1, cellBounds.Height - 1)); Color textColor = cellStyle.ForeColor; if ((cellState & DataGridViewElementStates.Selected) != 0) { using (SolidBrush backbrush = new SolidBrush(cellStyle.SelectionBackColor)) { graphics.FillRectangle(backbrush, cellRect); } textColor = cellStyle.SelectionForeColor; } else { using (SolidBrush backbrush = new SolidBrush(cellStyle.BackColor)) { graphics.FillRectangle(backbrush, cellRect); } using (Pen backpen = new Pen(this.DataGridView.BackgroundColor)) { graphics.DrawRectangle(backpen, cellBounds.Left - 1, cellBounds.Top - 1, cellBounds.Width, cellBounds.Height); } } StringFormat strFormat = new StringFormat(); // Set Alignment switch (cellStyle.Alignment) { case DataGridViewContentAlignment.BottomCenter: strFormat.LineAlignment = StringAlignment.Far; strFormat.Alignment = StringAlignment.Center; break; case DataGridViewContentAlignment.BottomLeft: strFormat.LineAlignment = StringAlignment.Far; strFormat.Alignment = StringAlignment.Near; break; case DataGridViewContentAlignment.BottomRight: strFormat.LineAlignment = StringAlignment.Far; strFormat.Alignment = StringAlignment.Far; break; case DataGridViewContentAlignment.MiddleCenter: strFormat.LineAlignment = StringAlignment.Center; strFormat.Alignment = StringAlignment.Center; break; case DataGridViewContentAlignment.MiddleLeft: strFormat.LineAlignment = StringAlignment.Center; strFormat.Alignment = StringAlignment.Near; break; case DataGridViewContentAlignment.MiddleRight: strFormat.LineAlignment = StringAlignment.Center; strFormat.Alignment = StringAlignment.Far; break; case DataGridViewContentAlignment.TopCenter: strFormat.LineAlignment = StringAlignment.Near; strFormat.Alignment = StringAlignment.Center; break; case DataGridViewContentAlignment.TopLeft: strFormat.LineAlignment = StringAlignment.Near; strFormat.Alignment = StringAlignment.Near; break; case DataGridViewContentAlignment.TopRight: strFormat.LineAlignment = StringAlignment.Near; strFormat.Alignment = StringAlignment.Far; break; } graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault; string outString; try { FarsiCalendarComponent.FarsiDate fd = new FarsiCalendarComponent.FarsiDate(); fd.GeoDate = (DateTime)value; outString = fd.FarsiDateValue; } catch { outString = ""; } using (SolidBrush textbrush = new SolidBrush(textColor)) { graphics.DrawString(outString, cellStyle.Font, textbrush, cellBounds, strFormat); } base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); }