コード例 #1
0
        private void TextBoxChanged(object sender, EventArgs e)
        {
            InputDataTextBox textBox = (InputDataTextBox)sender;

            for (int row = 0; row < textBoxes.GetLength(0); row++)
            {
                for (int column = 0; column < textBoxes.GetLength(1); column++)
                {
                    if (textBox.Equals(textBoxes[row, column]))
                    {
                        UpdateLabels(row, column);
                        //
                        int[,] textBoxValues = new int[2, 2];
                        textBoxValues[0, 0]  = (int)textBoxes[0, 0].Value;
                        textBoxValues[0, 1]  = (int)textBoxes[0, 1].Value;
                        textBoxValues[1, 0]  = (int)textBoxes[1, 0].Value;
                        textBoxValues[1, 1]  = (int)textBoxes[1, 1].Value;

                        /* в linq :
                         *
                         *  int[,] textBoxValues = textBoxes.Cast<InputDataTextBox>()
                         *  .Select((x, i) => new { x?.Value, i })
                         *  .Aggregate(
                         *    new int[textBoxes.GetLength(0), textBoxes.GetLength(1)],
                         *    (accum, item) =>
                         *    {
                         *        accum[item.i / textBoxes.GetLength(1), item.i % textBoxes.GetLength(1)] = (int)item.Value.GetValueOrDefault();
                         *        return accum;
                         *    });*/
                        //
                        textBoxUpdate.Invoke(textBoxValues);
                    }
                }
            }
        }
コード例 #2
0
        private void tbSettingValidatingInt(object sender, CancelEventArgs e)
        {
            InputDataTextBox textBox = (InputDataTextBox)sender;

            if (!Int32.TryParse(textBox.Text, out int value))
            {
                textBox.Text = textBox.LastState;
                MessageBox.Show("Введены недопустимые значения");
            }
        }