⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 macbox.cs

📁 快速切换网关
💻 CS
字号:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace MacBox
{
    public partial class MacBox : UserControl
    {
        private System.Windows.Forms.Panel panel1;
        private System.Windows.Forms.TextBox textBox1; 
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.TextBox textBox2;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox textBox3; 
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.TextBox textBox4;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.TextBox textBox5;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.TextBox textBox6;        
        private string _text = "";  

        public MacBox() 
        {             
            InitializeComponent();
        } 
        
        private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) 
        {
            textBox1.SelectedText = "";
            MaskIpAddr(textBox1, e);            
        } 

        private void textBox2_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) 
        {
            textBox2.SelectedText = "";
            MaskIpAddr(textBox2, e);            
        } 

        private void textBox3_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) 
        {
            textBox3.SelectedText = "";
            MaskIpAddr(textBox3, e);            
        } 

        private void textBox4_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) 
        {
            textBox4.SelectedText = "";
            MaskIpAddr(textBox4, e);            
        }

        private void textBox5_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            textBox5.SelectedText = "";
            MaskIpAddr(textBox5, e);
        }

        private void textBox6_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            textBox6.SelectedText = "";
            MaskIpAddr(textBox6, e);            
        }

        private void MaskIpAddr(System.Windows.Forms.TextBox textBox, KeyPressEventArgs e) 
        { 
            int len = textBox.Text.Length;
            if (e.KeyChar >= 'a' && e.KeyChar <= 'f')
            {
                e.KeyChar = (char)(Convert.ToInt32(e.KeyChar)-32);
            }
            if (Char.IsDigit(e.KeyChar) || e.KeyChar == '-' || e.KeyChar == 8 ||
                e.KeyChar == 'A' || e.KeyChar == 'B' || e.KeyChar == 'C' || 
                e.KeyChar == 'D' || e.KeyChar == 'E' || e.KeyChar == 'F')
            {
                if (e.KeyChar != 8)
                {
                    if (len == 1 && e.KeyChar != '-')
                    {
                        string tmp = textBox.Text + e.KeyChar;
                        if (textBox.Name == "textBox1")
                        {
                            textBox2.Focus();
                        }
                        else if (textBox.Name == "textBox2")
                        {
                            textBox3.Focus();
                        }
                        else if (textBox.Name == "textBox3")
                        {
                            textBox4.Focus();
                        }
                        else if (textBox.Name == "textBox4")
                        {
                            textBox5.Focus();
                        }
                        else if (textBox.Name == "textBox5")
                        {
                            textBox6.Focus();
                        }
                        else if (textBox.Name == "textBox6")
                        {
                            textBox1.Focus();
                        }
                    }

                    if (len < 2 && e.KeyChar == '-')
                    {                        
                        e.Handled = true;
                    } 
                }
            }
            else
            {
                e.Handled = true;
            }
        } 


        [Browsable(true)] 
         
        // 获取 IpBox 的文本。 
         
        public new string Text 
        { 
            get 
            { 
                if (textBox1.Text == "" 
                 || textBox2.Text == "" 
                 || textBox3.Text == "" 
                 || textBox4.Text == ""
                 || textBox5.Text == ""
                 || textBox6.Text == "") 
                { 
                    _text = ""; 
                    return _text; 
                } 
                else 
                {
                    _text = textBox1.Text + textBox2.Text + textBox3.Text + textBox4.Text + textBox5.Text + textBox6.Text; 
                    return _text; 
                }
            }
            set
            {
                _text = value;
                try
                {
                    if (value.Length == 12)
                    {
                        char[] txtValue = value.ToCharArray();
                        textBox1.Text = txtValue[0].ToString() + txtValue[1].ToString();
                        textBox2.Text = txtValue[2].ToString() + txtValue[3].ToString();
                        textBox3.Text = txtValue[4].ToString() + txtValue[5].ToString();
                        textBox4.Text = txtValue[6].ToString() + txtValue[7].ToString();
                        textBox5.Text = txtValue[8].ToString() + txtValue[9].ToString();
                        textBox6.Text = txtValue[10].ToString() + txtValue[11].ToString();
                    }
                    else
                    {
                        textBox1.Text = "";
                        textBox2.Text = "";
                        textBox3.Text = "";
                        textBox4.Text = "";
                        textBox5.Text = "";
                        textBox6.Text = "";
                        _text = "";
                    }
                }
                catch
                {
                    _text = "";
                }
            }
        }

        private void textBox1_Click(object sender, EventArgs e)
        {
            textBox1.SelectAll();
        }  

        private void textBox1_Enter(object sender, EventArgs e)
        {
            textBox1.SelectAll();
        }

        private void textBox2_Enter(object sender, EventArgs e)
        {
            textBox2.SelectAll();
        }

        private void textBox2_Click(object sender, EventArgs e)
        {
            textBox2.SelectAll();
        }

        private void textBox3_Enter(object sender, EventArgs e)
        {
            textBox3.SelectAll();
        }

        private void textBox3_Click(object sender, EventArgs e)
        {
            textBox3.SelectAll();
        }

        private void textBox4_Enter(object sender, EventArgs e)
        {
            textBox4.SelectAll();
        }

        private void textBox4_Click(object sender, EventArgs e)
        {
            textBox4.SelectAll();
        }

        private void textBox5_Enter(object sender, EventArgs e)
        {
            textBox5.SelectAll();
        }

        private void textBox5_Click(object sender, EventArgs e)
        {
            textBox5.SelectAll();
        }

        private void textBox6_Enter(object sender, EventArgs e)
        {
            textBox6.SelectAll();
        }

        private void textBox6_Click(object sender, EventArgs e)
        {
            textBox6.SelectAll();
        }
       
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -