void OnPlus(object sender, EventArgs e)
        {
            KeyEventArgs ke = new KeyEventArgs(Keys.Up);

            TheTimeBox_KeyDown(sender, ke);
            TheTimeBox.Select();
            TheTimeBox.Focus();
        }
Example #2
0
 private void SelectCorrectText(int SelectedIndex)
 {
     if (SelectedIndex <= 2)
     {
         TheTimeBox.Select(0, 2);
     }
     else if (SelectedIndex <= 5)
     {
         TheTimeBox.Select(3, 2);
     }
     else if (SelectedIndex <= 8)
     {
         TheTimeBox.Select(6, 2);
     }
     else
     {
         TheTimeBox.Select(9, 3);
     }
 }
Example #3
0
        private void TheTimeBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Up)
            {
                string[] Parts       = TheTimeBox.Text.Split(":".ToCharArray());
                string[] SecondParts = Parts[2].Split(".".ToCharArray());

                if (TheTimeBox.SelectionStart <= 2)
                {
                    int PartNum = 0;
                    if (int.TryParse(Parts[0], out PartNum))
                    {
                        PartNum++;
                        if (PartNum >= 100)
                        {
                            PartNum = 0;
                        }
                        Parts[0] = PartNum.ToString("D2");
                    }
                }
                else if (TheTimeBox.SelectionStart <= 5)
                {
                    int PartNum = 0;
                    if (int.TryParse(Parts[1], out PartNum))
                    {
                        PartNum++;
                        if (PartNum >= 60)
                        {
                            PartNum = 0;
                        }
                        Parts[1] = PartNum.ToString("D2");
                    }
                }
                else if (TheTimeBox.SelectionStart <= 8)
                {
                    int PartNum = 0;
                    if (int.TryParse(SecondParts[0], out PartNum))
                    {
                        PartNum++;
                        if (PartNum >= 60)
                        {
                            PartNum = 0;
                        }
                        SecondParts[0] = PartNum.ToString("D2");
                    }
                }
                else
                {
                    int PartNum = 0;
                    if (int.TryParse(SecondParts[1], out PartNum))
                    {
                        PartNum++;
                        if (PartNum >= 1000)
                        {
                            PartNum = 0;
                        }
                        SecondParts[1] = PartNum.ToString("D3");
                    }
                }
                SetText(Parts[0], Parts[1], SecondParts[0], SecondParts[1]);
                FormatText();
                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Down)
            {
                string[] Parts       = TheTimeBox.Text.Split(":".ToCharArray());
                string[] SecondParts = Parts[2].Split(".".ToCharArray());

                if (TheTimeBox.SelectionStart <= 2)
                {
                    int PartNum = 0;
                    if (int.TryParse(Parts[0], out PartNum))
                    {
                        PartNum--;
                        if (PartNum < 0)
                        {
                            PartNum = 23;
                        }
                        Parts[0] = PartNum.ToString("D2");
                    }
                }
                else if (TheTimeBox.SelectionStart <= 5)
                {
                    int PartNum = 0;
                    if (int.TryParse(Parts[1], out PartNum))
                    {
                        PartNum--;
                        if (PartNum < 0)
                        {
                            PartNum = 59;
                        }
                        Parts[1] = PartNum.ToString("D2");
                    }
                }
                else if (TheTimeBox.SelectionStart <= 8)
                {
                    int PartNum = 0;
                    if (int.TryParse(SecondParts[0], out PartNum))
                    {
                        PartNum--;
                        if (PartNum < 0)
                        {
                            PartNum = 59;
                        }
                        SecondParts[0] = PartNum.ToString("D2");
                    }
                }
                else
                {
                    int PartNum = 0;
                    if (int.TryParse(SecondParts[1], out PartNum))
                    {
                        PartNum--;
                        if (PartNum < 0)
                        {
                            PartNum = 999;
                        }
                        SecondParts[1] = PartNum.ToString("D3");
                    }
                }
                SetText(Parts[0], Parts[1], SecondParts[0], SecondParts[1]);
                FormatText();
                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Enter)
            {
                FormatText();
                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Left)
            {
                FormatText();
                if (TheTimeBox.SelectionStart <= 2)
                {
                    TheTimeBox.Select(9, 3);
                }
                else if (TheTimeBox.SelectionStart <= 5)
                {
                    TheTimeBox.Select(0, 2);
                }
                else if (TheTimeBox.SelectionStart <= 8)
                {
                    TheTimeBox.Select(3, 2);
                }
                else
                {
                    TheTimeBox.Select(6, 2);
                }
                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Right)
            {
                FormatText();
                if (TheTimeBox.SelectionStart <= 2)
                {
                    TheTimeBox.Select(3, 2);
                }
                else if (TheTimeBox.SelectionStart <= 5)
                {
                    TheTimeBox.Select(6, 2);
                }
                else if (TheTimeBox.SelectionStart <= 8)
                {
                    TheTimeBox.Select(9, 3);
                }
                else
                {
                    TheTimeBox.Select(0, 2);
                }
                e.Handled = true;
            }
            else if (!((e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9) || (e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9)))
            {
                NonNumKeyPressed = true;
                e.Handled        = true;
            }
        }