Пример #1
0
    private void TextBox_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Up)
        {
            IncrementIndex(sender);
        }
        else if (e.KeyCode == Keys.Down)
        {
            DecrementIndex(sender);
        }
        else if (e.KeyCode == Keys.Enter)
        {
            Point point = GetControlLocation(sender);
            if (point.Y > 0)
            {
                Control index_control = controls[point.X, 0] as TextBox;
                if (index_control != null)
                {
                    long value = 0L;
                    if (long.TryParse((sender as TextBox).Text, out value))
                    {
                        int index = 0;
                        switch (point.Y)
                        {
                        case 1:
                            index = Numbers.PrimeIndexOf(value) + 1;
                            break;

                        case 2:
                            index = Numbers.AdditivePrimeIndexOf(value) + 1;
                            break;

                        case 3:
                            index = Numbers.NonAdditivePrimeIndexOf(value) + 1;
                            break;

                        case 4:
                            index = Numbers.CompositeIndexOf(value) + 1;
                            break;

                        case 5:
                            index = Numbers.AdditiveCompositeIndexOf(value) + 1;
                            break;

                        case 6:
                            index = Numbers.NonAdditiveCompositeIndexOf(value) + 1;
                            break;

                        case 7:
                            index = Numbers.DeficientIndexOf(value) + 1;
                            break;

                        case 8:
                            index = Numbers.AbundantIndexOf(value) + 1;
                            break;

                        default:
                            index = 0;
                            break;
                        }
                        index_control.Text = index.ToString();

                        if (index == 0)
                        {
                            (sender as TextBox).Text = "";
                            index_control.Text       = "";
                        }
                    }
                }
            }
        }
    }