Beispiel #1
0
        private void timebox_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tbox = sender as TextBox;

            if (tbox == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(tbox.Text))
            {
                TimeInputType timeInputType = (TimeInputType)int.Parse(tbox.Tag.ToString());

                switch (timeInputType)
                {
                case TimeInputType.Hours:
                {
                    tbox.Text = DefaultHourValue;
                    break;
                }

                case TimeInputType.Minutes:
                {
                    tbox.Text = DefaultMinuteValue;
                    break;
                }
                }
            }
        }
Beispiel #2
0
        private bool _IsValidTime(string inputText, TimeInputType timeInputType)
        {
            //ertfertertert

            bool valudationResult = false;

            switch (timeInputType)
            {
            case TimeInputType.Hours:
                valudationResult = TimeInputValidation.IsValidHours(inputText);
                break;

            case TimeInputType.Minutes:
                valudationResult = TimeInputValidation.IsValidMinutes(inputText);
                break;

            case TimeInputType.Seconds:
                valudationResult = TimeInputValidation.IsValidSeconds(inputText);
                break;
            }

            return(valudationResult);
        }
Beispiel #3
0
        private void box_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            TextBox tbox = sender as TextBox;

            if (tbox == null)
            {
                return;
            }

            if (_IsNumber(e.Key))
            {
                char          inputSymb     = _TransformKeyToChar(e.Key);
                TimeInputType timeInputType = (TimeInputType)int.Parse(tbox.Tag.ToString());

                if (tbox.Text.Length == LENGTH_INPUT_STRING)
                {
                    if (tbox.SelectionStart == LENGTH_INPUT_STRING &&
                        (
                            (TimeInputType)int.Parse(tbox.Tag.ToString()) == TimeInputType.Hours ||
                            ((TimeInputType)int.Parse(tbox.Tag.ToString()) == TimeInputType.Minutes) && SecondsVisible == System.Windows.Visibility.Visible)
                        )
                    {
                        tbox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Right));

                        if ((TimeInputType)int.Parse(tbox.Tag.ToString()) == TimeInputType.Hours)
                        {
                            minutes.Text           = inputSymb.ToString();
                            minutes.SelectionStart = minutes.Text.Length;
                        }

                        if ((TimeInputType)int.Parse(tbox.Tag.ToString()) == TimeInputType.Minutes)
                        {
                            seconds.Text           = inputSymb.ToString();
                            seconds.SelectionStart = seconds.Text.Length;
                        }
                    }

                    e.Handled = true;
                    return;
                }

                string resultInput = tbox.SelectionStart == 0
                    ? inputSymb + tbox.Text
                    : tbox.Text + inputSymb;

                e.Handled = !_IsValidTime(resultInput, timeInputType);
                return;
            }

            if (e.Key == Key.Back &&
                (TimeInputType)int.Parse(tbox.Tag.ToString()) != TimeInputType.Hours &&
                tbox.SelectionStart == 0)
            {
                tbox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Left));
            }

            if (e.Key == Key.Right &&
                ((TimeInputType)int.Parse(tbox.Tag.ToString()) == TimeInputType.Hours ||
                 ((TimeInputType)int.Parse(tbox.Tag.ToString()) == TimeInputType.Minutes) && SecondsVisible == System.Windows.Visibility.Visible) &&
                tbox.SelectionStart == LENGTH_INPUT_STRING)
            {
                tbox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Right));
            }

            if (e.Key == Key.Left &&
                ((TimeInputType)int.Parse(tbox.Tag.ToString()) == TimeInputType.Minutes || (TimeInputType)int.Parse(tbox.Tag.ToString()) == TimeInputType.Seconds) &&
                tbox.SelectionStart == 0)
            {
                tbox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Left));
            }

            //if (e.Key == Key.Back &&
            //    tbox.SelectionStart == 0 &&
            //    (string)tbox.Tag != "0" &&
            //    tbox.SelectionLength != 2)
            //{
            //    tbox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Left));
            //}

            //if (e.Key == Key.Right &&
            //    tbox.SelectionStart == 2 &&
            //    ((string)tbox.Tag == "0" || ((string)tbox.Tag == "1") && SecondsVisible == System.Windows.Visibility.Visible))
            //{
            //    tbox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Right));
            //}

            //if (e.Key == Key.Left &&
            //    tbox.SelectionStart == 0 &&
            //    ((string)tbox.Tag == "1" || (string)tbox.Tag == "2"))
            //{
            //    tbox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Left));
            //}

            if (!(e.Key == Key.Back ||
                  e.Key == Key.Delete ||
                  e.Key == Key.Right ||
                  e.Key == Key.Left))
            {
                e.Handled = true;
            }
        }
Beispiel #4
0
        private bool _IsValidTime(string inputText, TimeInputType timeInputType)
        {
            //ertfertertert

            bool valudationResult = false;

            switch (timeInputType)
            {
                case TimeInputType.Hours:
                    valudationResult = TimeInputValidation.IsValidHours(inputText);
                    break;
                case TimeInputType.Minutes:
                    valudationResult = TimeInputValidation.IsValidMinutes(inputText);
                    break;
                case TimeInputType.Seconds:
                    valudationResult = TimeInputValidation.IsValidSeconds(inputText);
                    break;
            }

            return valudationResult;
        }