public void DateTimePicker_Format_Set_GetReturnsExpected(DateTimePickerFormat value) { using var control = new SubDateTimePicker(); control.Format = value; Assert.Equal(value, control.Format); }
// Показывает на экране элемент для ввода даты и времени public static void EnterDateTimeCell(DataGridView dataGridView, DataGridViewCellEventArgs e, DateTimePickerFormat dateTimePickerFormat) { if (dataGridView.Columns[e.ColumnIndex].ValueType == typeof(DateTime)) { CreateDateTimePicker(); currentDataGridView = dataGridView; dtpEventDatePicker.Tag = e; //dtpEventDatePicker.TextChanged += new EventHandler(dtpEventDatePicker_TextChanged); if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value is DateTime) dtpEventDatePicker.Value = (DateTime)dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; else dtpEventDatePicker.Value = DateTime.Today; dtpEventDatePicker.Format = dateTimePickerFormat; if (dtpEventDatePicker.Format == DateTimePickerFormat.Time) dtpEventDatePicker.ShowUpDown = true; else dtpEventDatePicker.ShowUpDown = false; dtpEventDatePicker.Parent = dataGridView; dtpEventDatePicker.Bounds = dataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false); dtpEventDatePicker.Visible = !dataGridView.ReadOnly; } }
public DateTimePicker() { base.SetState2(0x800, true); base.SetStyle(ControlStyles.FixedHeight, true); base.SetStyle(ControlStyles.StandardClick | ControlStyles.UserPaint, false); this.format = DateTimePickerFormat.Long; }
/// <summary> /// Constructor for the KryptonDataGridViewDateTimePickerCell cell type /// </summary> public KryptonDataGridViewDateTimePickerCell() { // Create a thread specific KryptonDateTimePicker control used for the painting of the non-edited cells if (_paintingDateTime == null) { _paintingDateTime = new KryptonDateTimePicker { ShowBorder = false }; _paintingDateTime.StateCommon.Border.Width = 0; _paintingDateTime.StateCommon.Border.Draw = InheritBool.False; } // Set the default values of the properties: _showCheckBox = false; _showUpDown = false; _autoShift = false; _checked = false; _customFormat = string.Empty; _customNullText = " "; _maxDate = DateTime.MaxValue; _minDate = DateTime.MinValue; _format = DateTimePickerFormat.Long; _calendarDimensions = new Size(1, 1); _calendarTodayText = "Today:"; _calendarFirstDayOfWeek = Day.Default; _calendarShowToday = true; _calendarCloseOnTodayClick = false; _calendarShowTodayCircle = true; _calendarShowWeekNumbers = false; _calendarTodayDate = DateTime.Now.Date; }
/// <summary> /// Sets the date shown in the textbox by a given value and format type. /// </summary> /// <param name="date"></param> /// <param name="formatType"></param> public override void SetDateByValue(DateTime?date, DateTimePickerFormat formatType) { CultureInfo info = Thread.CurrentThread.CurrentCulture; maskEditValueChanged = false; Thread.CurrentThread.CurrentCulture = this.dateTimePickerElement.Culture; this.textBoxElement.Culture = this.dateTimePickerElement.Culture; if (date != this.dateTimePickerElement.NullDate) { switch (formatType) { case DateTimePickerFormat.Time: if (this.dateTimePickerElement.ShowCurrentTime) { if (!date.HasValue) { date = DateTime.Now; } else { date = new DateTime(date.Value.Year, date.Value.Month, date.Value.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Millisecond, date.Value.Kind); } } this.textBoxElement.Mask = "T"; break; case DateTimePickerFormat.Short: this.textBoxElement.Mask = "d"; break; case DateTimePickerFormat.Long: this.textBoxElement.Mask = "D"; break; case DateTimePickerFormat.Custom: this.textBoxElement.Mask = this.dateTimePickerElement.CustomFormat; break; } if (!this.textBoxElement.Value.Equals(date)) { this.textBoxElement.Value = date; } } else { if (!this.textBoxElement.Value.Equals(date)) { this.textBoxElement.Value = date; } this.textBoxElement.Text = this.textBoxElement.TextBoxItem.NullText; } Thread.CurrentThread.CurrentCulture = info; maskEditValueChanged = true; }
private void FormatComboBox_SelectedIndexChanged(object sender, EventArgs e) { DateTimePickerFormat format = (DateTimePickerFormat)FormatComboBox.SelectedItem; SampleDateTimePicker.Format = format; DateTimePickerLayoutPanel.PerformLayout(); UpdateCustomFormatTextBox(); }
private TextBox _textBox; //TextBox Decorated when in ReadOnly Mode #endregion #region Constructor /// <summary> /// Basic Constructer + ReadOnly _textBox initialization /// </summary> public UltraDateTimePicker() { InitializeComponent(); initTextBox(); base.Format = DateTimePickerFormat.Custom; _Format = DateTimePickerFormat.Long; if (DesignMode) { setFormat(); } }
private void ucDatePicker_Load(object sender, EventArgs e) { datePicker.Value = DateTime.Today; if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["DatePickerFormat"])) { DateTimePickerFormat format; DateTimePickerFormat.TryParse(ConfigurationManager.AppSettings["DatePickerFormat"], out format); datePicker.Format = format; } if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["DatePickerCustomFormat"])) { datePicker.CustomFormat = ConfigurationManager.AppSettings["DatePickerCustomFormat"]; } }
public static string GetFormat(DateTimePickerFormat format) { switch (format) { case DateTimePickerFormat.Long: return("D"); case DateTimePickerFormat.Short: return("d"); case DateTimePickerFormat.Time: return("T"); } return(""); }
public override void SetDateByValue(DateTime?date, DateTimePickerFormat formatType) { CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; this.maskEditValueChanged = false; Thread.CurrentThread.CurrentCulture = this.dateTimePickerElement.Culture; this.textBoxElement.Culture = this.dateTimePickerElement.Culture; DateTime?nullable = date; DateTime nullDate = this.dateTimePickerElement.NullDate; if ((!nullable.HasValue ? 1 : (nullable.GetValueOrDefault() != nullDate ? 1 : 0)) != 0) { switch (formatType) { case DateTimePickerFormat.Long: this.textBoxElement.Mask = "D"; break; case DateTimePickerFormat.Short: this.textBoxElement.Mask = "d"; break; case DateTimePickerFormat.Time: if (this.dateTimePickerElement.ShowCurrentTime) { date = date.HasValue ? new DateTime?(new DateTime(date.Value.Year, date.Value.Month, date.Value.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Millisecond, date.Value.Kind)) : new DateTime?(DateTime.Now); } this.textBoxElement.Mask = "T"; break; case DateTimePickerFormat.Custom: this.textBoxElement.Mask = this.dateTimePickerElement.CustomFormat; break; } this.textBoxElement.Value = (object)date; } else { if (!this.textBoxElement.Value.Equals((object)date)) { this.textBoxElement.Value = (object)date; } this.textBoxElement.Text = this.textBoxElement.TextBoxItem.NullText; } Thread.CurrentThread.CurrentCulture = currentCulture; this.maskEditValueChanged = true; }
/// <summary> /// Raises the PaintCell event /// </summary> /// <param name="e">A PaintCellEventArgs that contains the event data</param> public override void OnPaintCell(PaintCellEventArgs e) { if (e.Table.ColumnModel.Columns[e.Column] is DateTimeColumn) { DateTimeColumn column = (DateTimeColumn)e.Table.ColumnModel.Columns[e.Column]; this.DateTimeFormat = column.DateTimeFormat; this.Format = column.CustomDateTimeFormat; } else { this.DateTimeFormat = DateTimePickerFormat.Long; this.Format = ""; } base.OnPaintCell(e); }
void SetFormat(DateTimePickerFormat f) { format = f; if (format == DateTimePickerFormat.Long) { customformat = CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern.Trim(); } else if (format == DateTimePickerFormat.Short) { customformat = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern.Trim(); } else if (format == DateTimePickerFormat.Time) { customformat = CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern.Trim(); } Recalc(); }
/// <summary> /// Adds a DateTime picker field /// </summary> /// <param name="sLabel">Label string</param> /// <param name="eFormat">DateTimePickerFormat to control the visual component</param> /// <param name="dtValue">The default date time value</param> /// <param name="zQueryKey">The query key for requesting the value</param> /// <returns></returns> public DateTimePicker AddDateTimePicker(string sLabel, DateTimePickerFormat eFormat, DateTime dtValue, object zQueryKey) { var zLabel = CreateLabel(sLabel); var zPicker = new DateTimePicker { Format = eFormat, Value = dtValue }; switch (eFormat) { case DateTimePickerFormat.Time: zPicker.ShowUpDown = true; break; } SetupControl(zPicker, zLabel, ControlType.DateTimePicker, true, zQueryKey); return(zPicker); }
private void MetroFrameworkDateTimePicker_ValueChanged(object sender, EventArgs e) { if (!DesignMode) { if (ShowCheckBox) { if (Checked) { Format = BufferedFormat; } else { BufferedFormat = Format; Format = DateTimePickerFormat.Custom; CustomFormat = " "; } } } }
public ToolStripDateTimePicker(string name, DateTimePickerFormat format) : base(new DateTimePicker(), name) { Name = name; Format = format; }
/// <summary> /// Initializes the DateTimeColumn with default values /// </summary> internal void Init() { this.dateFormat = DateTimePickerFormat.Long; this.customFormat = DateTimeFormatInfo.CurrentInfo.ShortDatePattern + " " + DateTimeFormatInfo.CurrentInfo.LongTimePattern; }
public ToolStripDateTimePicker(DateTimePickerFormat format) : base(new DateTimePicker()) { Format = format; }
/// <summary> /// Raises the PaintCell event /// </summary> /// <param name="e">A PaintCellEventArgs that contains the event data</param> public override void OnPaintCell(PaintCellEventArgs e) { if (e.Table.ColumnModel.Columns[e.Column] is DateTimeColumn) { DateTimeColumn column = (DateTimeColumn) e.Table.ColumnModel.Columns[e.Column]; this.DateTimeFormat = column.DateTimeFormat; this.Format = column.CustomDateTimeFormat; } else { this.DateTimeFormat = DateTimePickerFormat.Long; this.Format = ""; } base.OnPaintCell(e); }
/// <summary> /// Initializes a new instance of the DateTimeCellRenderer class with /// default settings /// </summary> public DateTimeCellRenderer() : base() { this.dateFormat = DateTimePickerFormat.Long; this.Format = DateTimeColumn.LongDateFormat; }
public DataGridViewDateTimeCell() { _format = DateTimePickerFormat.Custom; _customFormat = "dd/MM/yyyy"; _showUpDown = false; }
/// <summary> /// Adds a DateTime picker field /// </summary> /// <param name="sLabel">Label string</param> /// <param name="eFormat">DateTimePickerFormat to control the visual component</param> /// <param name="dtValue">The default date time value</param> /// <param name="zQueryKey">The query key for requesting the value</param> /// <returns></returns> public DateTimePicker AddDateTimePicker(string sLabel, DateTimePickerFormat eFormat, DateTime dtValue, object zQueryKey) { var zLabel = CreateLabel(sLabel); var zPicker = new DateTimePicker { Format = eFormat, Value = dtValue }; switch (eFormat) { case DateTimePickerFormat.Time: zPicker.ShowUpDown = true; break; } SetupControl(zPicker, zLabel, ControlType.DateTimePicker, true, zQueryKey); return zPicker; }
private void prepararDatePickerConFormato(DateTimePicker picker, DateTime?fecha, DateTimePickerFormat formatoSiValido) { if (fecha == null) { picker.Format = DateTimePickerFormat.Custom; picker.CustomFormat = " "; } else { picker.Format = formatoSiValido; picker.Text = fecha.GetValueOrDefault().ToShortTimeString(); } }
/// <include file='doc\DateTimePicker.uex' path='docs/doc[@for="DateTimePicker.DateTimePicker"]/*' /> /// <devdoc> /// <para>Initializes a new instance of the <see cref='System.Windows.Forms.DateTimePicker'/> class.</para> /// </devdoc> public DateTimePicker() : base() { // this class overrides GetPreferredSizeCore, let Control automatically cache the result SetState2(STATE2_USEPREFERREDSIZECACHE, true); SetStyle(ControlStyles.FixedHeight, true); // Since DateTimePicker does its own mouse capturing, we do not want // to receive standard click events, or we end up with mismatched mouse // button up and button down messages. // SetStyle(ControlStyles.UserPaint | ControlStyles.StandardClick, false); // Set default flags here... // format = DateTimePickerFormat.Long; }
private void UpdateCustomFormatTextBox() { DateTimePickerFormat format = (DateTimePickerFormat)FormatComboBox.SelectedItem; CustomFormatTextBox.Enabled = format == DateTimePickerFormat.Custom; }
public PropertyDateTimeLook(DateTimePickerFormat format) { _format = format; }
public static void Set_Format(this WNFRMS.Viewmodels.DateTimePickerViewModel _DateTimePicker, DateTimePickerFormat Format) { throw new NotImplementedException("This is an automatic generated code, please implement the requested logic."); }
/// <summary> /// Sets Format of DateTimePicker control /// </summary> /// <param name="builder"></param> /// <param name="format"></param> /// <returns></returns> public static DialogSetOptionsWithSpecifiedControlBuilder <DateTimePicker, DateTime> HasFormat (this DialogSetOptionsWithSpecifiedControlBuilder <DateTimePicker, DateTime> builder, DateTimePickerFormat format) { var control = builder.Item.Data.Control as DateTimePicker; control.Format = format; return(builder); }
public PropertyDateTimeLook(string customFormat) { _format = DateTimePickerFormat.Custom; _customFormat = customFormat; }
internal void SetFormat(int rowIndex, DateTimePickerFormat value) { _format = value; if (OwnsEditingdateTimePicker(rowIndex)) { EditingDateTimePicker.Format = value; } }
public void DateTimePicker_Format_SetInvalid_ThrowsInvalidEnumArgumentException(DateTimePickerFormat value) { using var control = new DateTimePicker(); Assert.Throws <InvalidEnumArgumentException>("value", () => control.Format = value); }
// only public constructor public DateTimePicker () { // initialise the month calendar month_calendar = new MonthCalendar (this); month_calendar.CalendarDimensions = new Size (1, 1); month_calendar.MaxSelectionCount = 1; month_calendar.ForeColor = Control.DefaultForeColor; month_calendar.BackColor = DefaultMonthBackColor; month_calendar.TitleBackColor = DefaultTitleBackColor; month_calendar.TitleForeColor = DefaultTitleForeColor; month_calendar.TrailingForeColor = DefaultTrailingForeColor; month_calendar.Visible = false; // initialize the timer updown_timer = new Timer(); updown_timer.Interval = initial_timer_delay; // initialise other variables is_checked = true; custom_format = null; drop_down_align = LeftRightAlignment.Left; format = DateTimePickerFormat.Long; max_date = MaxDateTime; min_date = MinDateTime; show_check_box = false; show_up_down = false; date_value = DateTime.Now; is_drop_down_visible = false; BackColor = SystemColors.Window; ForeColor = SystemColors.WindowText; month_calendar.DateChanged += new DateRangeEventHandler (MonthCalendarDateChangedHandler); month_calendar.DateSelected += new DateRangeEventHandler (MonthCalendarDateSelectedHandler); month_calendar.LostFocus += new EventHandler (MonthCalendarLostFocusHandler); updown_timer.Tick += new EventHandler (UpDownTimerTick); KeyPress += new KeyPressEventHandler (KeyPressHandler); KeyDown += new KeyEventHandler (KeyDownHandler); GotFocus += new EventHandler (GotFocusHandler); LostFocus += new EventHandler (LostFocusHandler); MouseDown += new MouseEventHandler (MouseDownHandler); MouseUp += new MouseEventHandler (MouseUpHandler); MouseEnter += new EventHandler (OnMouseEnter); MouseLeave += new EventHandler (OnMouseLeave); MouseMove += new MouseEventHandler (OnMouseMove); Paint += new PaintEventHandler (PaintHandler); Resize += new EventHandler (ResizeHandler); SetStyle (ControlStyles.UserPaint | ControlStyles.StandardClick, false); SetStyle (ControlStyles.FixedHeight, true); SetStyle (ControlStyles.Selectable, true); CalculateFormats (); }
public void SetFormat(DateTimePickerFormat format) { dateInEdit.Format = format; dateOutEdit.Format = format; }
public override void SetDateByValue(DateTime?date, DateTimePickerFormat formatType) { CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; this.maskEditValueChanged = false; Thread.CurrentThread.CurrentCulture = this.Calendar.Culture; this.textBoxElement.Culture = this.Calendar.Culture; DateTime?nullable1 = date; DateTime nullDate = this.DateTimePickerElement.NullDate; if ((!nullable1.HasValue ? 1 : (nullable1.GetValueOrDefault() != nullDate ? 1 : 0)) != 0) { DateTime?nullable2 = date; DateTime focusedDate = this.calendar.FocusedDate; if ((!nullable2.HasValue ? 1 : (nullable2.GetValueOrDefault() != focusedDate ? 1 : 0)) != 0 && date.HasValue) { this.calendar.FocusedDate = date.Value; if (this.showTimePicker && this.timePicker != null) { this.timePicker.Value = (object)date.Value; } } bool flag = false; MaskDateTimeProvider provider1 = this.textBoxElement.Provider as MaskDateTimeProvider; if (provider1 != null) { flag = provider1.AutoSelectNextPart; } switch (formatType) { case DateTimePickerFormat.Long: this.textBoxElement.Mask = "D"; break; case DateTimePickerFormat.Short: this.textBoxElement.Mask = "d"; break; case DateTimePickerFormat.Time: if (this.dateTimePickerElement.ShowCurrentTime) { date = date.HasValue ? new DateTime?(new DateTime(date.Value.Year, date.Value.Month, date.Value.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Millisecond, date.Value.Kind)) : new DateTime?(DateTime.Now); } this.textBoxElement.Mask = "T"; break; case DateTimePickerFormat.Custom: this.textBoxElement.Mask = this.dateTimePickerElement.CustomFormat; break; } MaskDateTimeProvider provider2 = this.textBoxElement.Provider as MaskDateTimeProvider; if (provider2 != null) { provider2.AutoSelectNextPart = flag; } if (this.textBoxElement.Value == null) { this.textBoxElement.Value = (object)date; } if (!this.textBoxElement.IsKeyBoard) { this.textBoxElement.Value = (object)date; } } else if (!this.textBoxElement.IsKeyBoard) { if (this.textBoxElement.Value != null && !this.textBoxElement.Value.Equals((object)date)) { this.textBoxElement.Value = (object)date; } this.textBoxElement.TextBoxItem.Text = ""; } Thread.CurrentThread.CurrentCulture = currentCulture; this.maskEditValueChanged = true; }
public abstract void SetDateByValue(DateTime?date, DateTimePickerFormat formatType);