Ejemplo n.º 1
0
        private void SetTextBox(string[] nums)
        {
            checked
            {
                for (int i = 0; i < nums.Length; i++)
                {
                    string text = nums[i];
                    if (IPTextBox.IsNumeric(text))
                    {
                        int num = int.Parse(text);
                        if (i == 0)
                        {
                            if (this._inputType == InputType.IPAddress)
                            {
                                if (num < 1 && num > 233 && this._showErrorFlag)
                                {
                                    this.errVerify.SetError(this, "无效的 IP 地址。");
                                }
                            }
                            else
                            {
                                if (num < 0 && num > 255 && this._showErrorFlag)
                                {
                                    this.errVerify.SetError(this, "无效的 IP 地址。");
                                }
                            }
                            this.textBox1.Text = num.ToString();
                        }
                        if (i > 0)
                        {
                            if (num < 0 && num > 255 && this._showErrorFlag)
                            {
                                this.errVerify.SetError(this, "无效的 IP 地址。");
                            }
                            switch (i)
                            {
                            case 1:
                                this.textBox2.Text = num.ToString();
                                break;

                            case 2:
                                this.textBox3.Text = num.ToString();
                                break;

                            default:
                                this.textBox4.Text = num.ToString();
                                break;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void mnuPaste_Click(object sender, EventArgs e)
        {
            string text = Clipboard.GetText(TextDataFormat.Text);

            if (IPTextBox.IsNumeric(text))
            {
                if (int.Parse(text) > 255)
                {
                    if (this._showErrorFlag)
                    {
                        this.errVerify.SetError(this, "你正试图粘贴错误格式的IP地址!");
                    }
                    else
                    {
                        MessageBox.Show("你正试图粘贴错误格式的IP地址!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    TextBox textBox = ((sender as ToolStripMenuItem).Owner as ContextMenuStrip).SourceControl as TextBox;
                    int     num     = 255;
                    if (this._inputType == InputType.Gateway)
                    {
                        num = 255;
                    }
                    if (textBox.Name == "textBox1")
                    {
                        if (int.Parse(text) > num)
                        {
                            textBox.Text = num.ToString();
                            textBox.Focus();
                            if (this._showErrorFlag)
                            {
                                this.errVerify.SetError(this, "请指定一个介于 1 和 255 之间的数值。");
                            }
                            else
                            {
                                MessageBox.Show(text + " 不是一个有效项目。请指定一个介于 1 和 255 之间的数值。", "出错", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                        else
                        {
                            textBox.Text = text;
                            this.textBox2.Focus();
                            this.textBox2.SelectAll();
                        }
                    }
                    else
                    {
                        if (textBox.Name == "textBox2")
                        {
                            if (int.Parse(text) > 255)
                            {
                                textBox.Text = "255";
                                textBox.Focus();
                                if (this._showErrorFlag)
                                {
                                    this.errVerify.SetError(this, "请指定一个介于 1 和 255 之间的数值。");
                                }
                                else
                                {
                                    MessageBox.Show(text + " 不是一个有效项目。请指定一个介于 1 和 255 之间的数值。", "出错", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                }
                            }
                            else
                            {
                                textBox.Text = text;
                                this.textBox3.Focus();
                                this.textBox3.SelectAll();
                            }
                        }
                        else
                        {
                            if (textBox.Name == "textBox3")
                            {
                                if (int.Parse(text) > 255)
                                {
                                    textBox.Text = "255";
                                    textBox.Focus();
                                    if (this._showErrorFlag)
                                    {
                                        this.errVerify.SetError(this, "请指定一个介于 1 和 255 之间的数值。");
                                    }
                                    else
                                    {
                                        MessageBox.Show(text + " 不是一个有效项目。请指定一个介于 1 和 255 之间的数值。", "出错", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    }
                                }
                                else
                                {
                                    textBox.Text = text;
                                    this.textBox4.Focus();
                                    this.textBox4.SelectAll();
                                }
                            }
                            else
                            {
                                if (textBox.Name == "textBox4")
                                {
                                    if (int.Parse(text) > 255)
                                    {
                                        textBox.Text = "255";
                                        textBox.Focus();
                                        if (this._showErrorFlag)
                                        {
                                            this.errVerify.SetError(this, "请指定一个介于 1 和 255 之间的数值。");
                                        }
                                        else
                                        {
                                            MessageBox.Show(text + " 不是一个有效项目。请指定一个介于 1 和 255 之间的数值。", "出错", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        }
                                    }
                                    else
                                    {
                                        textBox.Text = text;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (this._showErrorFlag)
                {
                    this.errVerify.SetError(this, "你正试图粘贴错误格式的IP地址!");
                }
                else
                {
                    MessageBox.Show("你正试图粘贴错误格式的IP地址!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }