Beispiel #1
0
        private void TxtZeroVolt_KeyPress(object sender, KeyPressEventArgs e)
        {
            switch (e.KeyChar)
            {
            case (char)13:     //Return
                TxtZeroVolt.Visible = false;

                zeroVoltPoint.fNumber = zeroVoltPoint.gFlt(TxtZeroVolt.Text);
                VoltDiv.fNumber       = VoltDiv.gFlt(this.CmbVoltDiv.Text);
                for (int i = 0; i < this.Lbl_V_Axis.GetUpperBound(0) + 1; i++)
                {
                    this.V_axis[i].fNumber  = (i - this.Lbl_V_Axis.GetUpperBound(0) / 2) * VoltDiv.fNumber + zeroVoltPoint.fNumber;
                    this.Lbl_V_Axis[i].Text = this.V_axis[i].gStr("V");
                }
                SendTransformParams();
                break;

            case (char)8:     //Backspace
                break;

            default:
                string Input = "";
                for (int i = 0; i <= TxtZeroVolt.SelectionStart - 1; i++)
                {
                    Input += TxtZeroVolt.Text[i];
                }
                Input += e.KeyChar;
                if (TxtZeroVolt.TextLength > 0)
                {
                    for (int i = TxtZeroVolt.SelectionStart + TxtZeroVolt.SelectionLength; i <= TxtZeroVolt.TextLength - 1; i++)
                    {
                        Input += TxtZeroVolt.Text[i];
                    }
                }
                if (Input[Input.Length - 1] != 'V')
                {
                    Input += 'V';
                }
                //string allValidChar = "-+0123456789mV,.";// + (char)8 + (char)127;
                string firstValidChar      = "-+0123456789";// + (char)8 + (char)127;
                string secondValidChar     = "0123456789mV,.";
                string bodyValidChar       = "0123456789,.";
                string secondlastValidChar = "0123456789,.m";
                string lastValidChar       = "mV";
                char[] InputArr            = Input.ToCharArray();
                int    Up = InputArr.GetUpperBound(0);
                if (Up > -1 && firstValidChar.IndexOf(InputArr[0]) == -1)
                {
                    InputArr[0] = '_';
                }
                if (Up > 0 && secondValidChar.IndexOf(InputArr[1]) == -1)
                {
                    InputArr[1] = '_';
                }
                for (int i = 2; i <= Up - 2; i++)
                {
                    if (bodyValidChar.IndexOf(InputArr[i]) == -1)
                    {
                        InputArr[i] = '_';
                    }
                }
                if (Up > 0 && secondlastValidChar.IndexOf(InputArr[Up - 1]) == -1)
                {
                    InputArr[Up - 1] = '_';
                }
                if (Up > 0 && lastValidChar.IndexOf(InputArr[Up]) == -1)
                {
                    InputArr[Up] = '_';
                }

                int len = 0; for (int i = 0; i <= InputArr.GetUpperBound(0); i++)
                {
                    if (InputArr[i] != '_')
                    {
                        len++;
                    }
                }
                char[] OutputArr = new char[len]; int y = 0;
                for (int i = 0; i <= InputArr.GetUpperBound(0); i++)
                {
                    if (InputArr[i] != '_')
                    {
                        OutputArr[y] = InputArr[i]; y++;
                    }
                }
                //OutputArr[OutputArr.GetUpperBound(0)] = "\n";
                this.TxtZeroVolt.Text = new string(OutputArr);
                if (TxtZeroVolt.Text.Length > 0)
                {
                    TxtZeroVolt.Select(TxtZeroVolt.Text.Length - 1, 0);
                }
                e.Handled = true;
                break;
            }
        }
Beispiel #2
0
 private void SetToZero_Click(object sender, EventArgs e)
 {
     TxtZeroVolt.Visible = true;
     TxtZeroVolt.Focus();
 }