Files
ayanova7/source/GZWFControls/GZDateTimePicker.cs
2018-06-29 19:47:36 +00:00

125 lines
4.2 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace GZTW.WinForm.Controls
{
public partial class GZDateTimePicker : Infragistics.Win.UltraWinEditors.UltraDateTimeEditor
{
private static bool InDesignMode
{
get
{
if (System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv")
return true;
if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
return true;
return false;
}
}
public GZDateTimePicker()
{
InitializeComponent();
this.ButtonsRight.Clear();
if (!InDesignMode)
{
SetInputMask();
InsertTimePickerButton();
}
}
/// <summary>
/// Use to properly enable control and time picker and date picker
/// </summary>
public bool GZEnabled
{
get
{
return this.Enabled;
}
set
{
this.Enabled = value;
if (this.ButtonsRight.Count > 0)
this.ButtonsRight[0].Visible = value;
}
}
/// <summary>
/// Use to properly enable control and time picker and date picker
/// </summary>
public bool GZReadOnly
{
get
{
return this.ReadOnly;
}
set
{
this.ReadOnly = value;
if (this.ButtonsRight.Count > 0)
this.ButtonsRight[0].Visible = !value;
}
}
private void InsertTimePickerButton()
{
//don't add the button if the control is non editable
if (this.ReadOnly || this.Enabled == false) return;
Infragistics.Win.UltraWinEditors.EditorButton btTimePicker = new Infragistics.Win.UltraWinEditors.EditorButton();
Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance();
appearance1.Image = Resource1.Time16;
btTimePicker.Appearance = appearance1;
this.ButtonsRight.Add(btTimePicker);
this.EditorButtonClick += new Infragistics.Win.UltraWinEditors.EditorButtonEventHandler(GZEditorButtonClick);
}
private void GZEditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
{
if (this.ReadOnly || this.Enabled == false) return;
TimePicker tp = new TimePicker(this);
tp.ShowDialog();
}
/// <summary>
/// Set the AyaNova standard localized input mask
/// </summary>
private void SetInputMask()
{
System.Globalization.CultureInfo ciCurrent = System.Globalization.CultureInfo.CurrentCulture;
Infragistics.Win.DateTimeEditor editor = new Infragistics.Win.DateTimeEditor();
string dateMask = editor.CalcDefaultDateMask(ciCurrent);
string timeMask = editor.CalcDefaultTimeMask(ciCurrent);
//Case 137
//.net doesn't set the short time format in the current culture object based on the
//regional settings, but instead sets the long time pattern instead since the regional
//settings only has one box to set a custom format in. Infragistics uses the incorrect
//pattern (short) so it doesn't pick up the customized setting in calcdefaulttimemask
//reported to infragistics and if they fix it I can revert this code back, but it probably internally
//just does the same thing anyway.
if (ciCurrent.DateTimeFormat.ShortTimePattern != ciCurrent.DateTimeFormat.LongTimePattern)
{
timeMask = "{longtime}";
}
this.MaskInput = dateMask + " " + timeMask;
}
//----------------------------------
}
}