示例#1
0
 public static DateTime ResetTime(this DateTime dt, int hms, HMSType hmsType)
 {
     return(new DateTime(dt.Year, dt.Month, dt.Day,
                         (hmsType == HMSType.Hour) || (hmsType == HMSType.HHour ||
                                                       hmsType == HMSType.hour) || (hmsType == HMSType.hhour) ? hms : dt.Hour,
                         (hmsType == HMSType.minute) || (hmsType == HMSType.mminute) ? hms : dt.Minute,
                         (hmsType == HMSType.second) || (hmsType == HMSType.ssecond) ? hms : dt.Second,
                         dt.Millisecond, dt.Kind));
 }
示例#2
0
        /// <param name="shortHMS">An HMS tag corresponding to 'H', 'h', 'm', 's', 't' </param>
        /// <param name="longHMS">An HMS tag corresponding to 'HH', 'hh', 'mm', 'ss', 'tt'</param>
        private int LoadTimeTag(string TimePattern, int Idx, HMSType shortHMS, HMSType longHMS)
        {
            if (Idx < TimePattern.Length - 1 && TimePattern[Idx + 1] == TimePattern[Idx])
            {
                AddHMSCtrl(longHMS);
                Idx++;
            }
            else
            {
                AddHMSCtrl(shortHMS);
            }

            return(Idx);
        }
示例#3
0
        private void AddHMSCtrl(HMSType hmsType)
        {
            TextBox tb = new TextBox();

            tb.set_HMSType(hmsType);
            tb.set_HMSText(Value);
            tb.Height          = ActualHeight;
            tb.Margin          = new Thickness(0.0);
            tb.BorderThickness = new Thickness();
            tb.Background      = Background;
            tb.Foreground      = TextBrush;
            tb.IsEnabled       = IsEnabled;

            if (hmsType == HMSType.t || hmsType == HMSType.tt)
            {
                tb.Focusable                   = true;
                tb.AllowDrop                   = false;
                tb.IsReadOnly                  = true;
                tb.IsUndoEnabled               = false;
                tb.GotKeyboardFocus           += new KeyboardFocusChangedEventHandler(tb_tt_GotKeyboardFocus);
                tb.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(tb_tt_PreviewMouseLeftButtonDown);
                tb.PreviewKeyDown             += new KeyEventHandler(tb_tt_PreviewKeyDown);
                tb.PreviewTextInput           += new TextCompositionEventHandler(tb_tt_PreviewTextInput);
            }
            else
            {
                tb.PreviewTextInput            += new TextCompositionEventHandler(tb_PreviewTextInput);
                tb.PreviewLostKeyboardFocus    += new KeyboardFocusChangedEventHandler(tb_PreviewLostKeyboardFocus);
                tb.GotKeyboardFocus            += new KeyboardFocusChangedEventHandler(tb_GotKeyboardFocus);
                tb.LostKeyboardFocus           += new KeyboardFocusChangedEventHandler(tb_LostKeyboardFocus);
                tb.PreviewKeyDown              += new KeyEventHandler(tb_PreviewKeyDown);
                tb.PreviewMouseLeftButtonDown  += new MouseButtonEventHandler(tb_PreviewMouseLeftButtonDown);
                tb.PreviewMouseRightButtonDown += new MouseButtonEventHandler(tb_PreviewMouseRightButtonDown);
                tb.PreviewQueryContinueDrag    += new QueryContinueDragEventHandler(tb_PreviewQueryContinueDrag);
                tb.PreviewDragEnter            += new DragEventHandler(tb_PreviewDrag);
                tb.PreviewDragOver             += new DragEventHandler(tb_PreviewDrag);
            }
            AddHMSCtrlContextMenu(tb);
            tb.PreviewMouseWheel += new MouseWheelEventHandler(tb_PreviewMouseWheel);
            AddGridCtrl(tb);
        }
示例#4
0
        private static void ValueChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TimeCtrl tc = d as TimeCtrl;

            if (tc != null && e.NewValue is DateTime)
            {
                foreach (UIElement ele in tc.TimeCtrls.Children)
                {
                    var ctrl = ele as FrameworkElement;

                    HMSType hmsType = ctrl.get_HMSType();

                    if (hmsType != HMSType.unknown)
                    {
                        var tb = ctrl as TextBox;
                        if (tb != null)
                        {
                            tb.set_HMSText((DateTime)e.NewValue);
                        }
                    }
                }
                tc.SetIsValidTime();
            }
        }
示例#5
0
 public static void set_HMSType(this FrameworkElement ctrl, HMSType hmsType)
 {
     ctrl.Name = hmsType.ToString();
 }
示例#6
0
        /// <param name="shortHMS">An HMS tag corresponding to 'H', 'h', 'm', 's', 't' </param>
        /// <param name="longHMS">An HMS tag corresponding to 'HH', 'hh', 'mm', 'ss', 'tt'</param>
        private int LoadTimeTag(string TimePattern, int Idx, HMSType shortHMS, HMSType longHMS)
        {
            if (Idx < TimePattern.Length - 1 && TimePattern[Idx + 1] == TimePattern[Idx])
            {
                AddHMSCtrl(longHMS);
                Idx++;
            }
            else
                AddHMSCtrl(shortHMS);

            return Idx;
        }
示例#7
0
 private void AddHMSCtrl(HMSType hmsType)
 {
     TextBox tb = new TextBox();
     tb.set_HMSType(hmsType);
     tb.set_HMSText(Value);
     tb.Height = ActualHeight;
     tb.Margin = new Thickness(0.0);
     tb.BorderThickness = new Thickness();
     tb.Background = Background;
     tb.Foreground = TextBrush;
     tb.IsEnabled = IsEnabled;
    
     if (hmsType == HMSType.t || hmsType == HMSType.tt)
     {
         tb.Focusable = true;
         tb.AllowDrop = false;
         tb.IsReadOnly = true;
         tb.IsUndoEnabled = false;
         tb.GotKeyboardFocus += new KeyboardFocusChangedEventHandler(tb_tt_GotKeyboardFocus);
         tb.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(tb_tt_PreviewMouseLeftButtonDown); 
         tb.PreviewKeyDown += new KeyEventHandler(tb_tt_PreviewKeyDown);
         tb.PreviewTextInput += new TextCompositionEventHandler(tb_tt_PreviewTextInput);
     }
     else
     {
         tb.PreviewTextInput += new TextCompositionEventHandler(tb_PreviewTextInput);
         tb.PreviewLostKeyboardFocus += new KeyboardFocusChangedEventHandler(tb_PreviewLostKeyboardFocus);
         tb.GotKeyboardFocus += new KeyboardFocusChangedEventHandler(tb_GotKeyboardFocus);
         tb.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(tb_LostKeyboardFocus);
         tb.PreviewKeyDown += new KeyEventHandler(tb_PreviewKeyDown);
         tb.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(tb_PreviewMouseLeftButtonDown);
         tb.PreviewMouseRightButtonDown += new MouseButtonEventHandler(tb_PreviewMouseRightButtonDown);
         tb.PreviewQueryContinueDrag += new QueryContinueDragEventHandler(tb_PreviewQueryContinueDrag);
         tb.PreviewDragEnter += new DragEventHandler(tb_PreviewDrag);
         tb.PreviewDragOver += new DragEventHandler(tb_PreviewDrag);                
     }
     AddHMSCtrlContextMenu(tb);
     tb.PreviewMouseWheel += new MouseWheelEventHandler(tb_PreviewMouseWheel);
     AddGridCtrl(tb);
 }