C#生成二进制文件

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class MAC : Form
{
public MAC()
{
InitializeComponent();
}
[StructLayoutAttribute(LayoutKind.Sequential)] //don’t need
struct ST_EEPROM_MAC
{
public Byte u8MacID0;
public Byte u8MacID1;
public Byte u8MacID2;
// public Byte[] u8MacAdress = new Byte[6];
// public Byte[] u8MacAdress;
public Byte[] u8MacAdress;
public Byte u8MacChecksum;
}

// string CreateMACLogName= "CreateMAC.log";
// string CreateMACLogFilePath = Directory.GetCurrentDirectory();
    string CreateMACLogFilePath = ".\\CreateMAC.log";
   
   
    //Write Log
    private void WriteLogFile(ulong MACNumber,int mode)
    {
        try
        {
         // CreateMACLogFilePath = CreateMACLogFilePath + CreateMACLogName; //why this method is wrong? can't create file in current file
            FileStream CreateLog = new FileStream(CreateMACLogFilePath, FileMode.OpenOrCreate);
            string CurrentTime = DateTime.Now.ToString();
            string LogRecoder = CurrentTime + "\r\n";
            if (1 == mode)
            {
                LogRecoder = LogRecoder + "Have create " + MACNumber.ToString() + " MAC\r\n";
                LogRecoder = LogRecoder + "Start MAC is: " + StartMACByte1.Text + ":" + StartMACByte2.Text + ":" + StartMACByte3.Text + ":" + StartMACByte4.Text + ":" + StartMACByte5.Text + ":" + StartMACByte6.Text + "\r\n";
                LogRecoder = LogRecoder + "End MAC is : " + EndMACByte1.Text + ":" + EndMACByte2.Text + ":" + EndMACByte3.Text + ":" + EndMACByte4.Text + ":" + EndMACByte5.Text + ":" + EndMACByte6.Text + "\r\n\r\n\r\n";
            }
            else if (0 == mode)
            {
                LogRecoder = LogRecoder + "Have create " + MACNumber.ToString() + " MAC\r\n";
                LogRecoder = LogRecoder + "The MAC is:" + Byte1.Text + ":" + Byte2.Text + ":" + Byte3.Text + ":" + Byte4.Text + ":" + Byte5.Text + ":" + Byte6.Text + "\r\n\r\n\r\n";
            }
            Encoding LogEncoder = Encoding.UTF8;
            Byte[] LogBytes = LogEncoder.GetBytes(LogRecoder);
            CreateLog.Position = CreateLog.Length;
            CreateLog.Write(LogBytes, 0, LogBytes.Length);
            CreateLog.Flush();
            CreateLog.Close();
            return;
        }
        catch //(System.Exception ex)
        {
            MessageBox.Show("Write Log failed!");
        }
    }
   
    private void ChangMacToBtye(ST_EEPROM_MAC MacAddr, Byte[] WriteArray)
    {
        WriteArray[0] = MacAddr.u8MacID0;
        WriteArray[1] = MacAddr.u8MacID1;
        WriteArray[2] = MacAddr.u8MacID2;
        WriteArray[3] = MacAddr.u8MacAdress[0];
        WriteArray[4] = MacAddr.u8MacAdress[1];
        WriteArray[5] = MacAddr.u8MacAdress[2];
        WriteArray[6] = MacAddr.u8MacAdress[3];
        WriteArray[7] = MacAddr.u8MacAdress[4];
        WriteArray[8] = MacAddr.u8MacAdress[5];
        WriteArray[9] = MacAddr.u8MacChecksum;
    }
    private void button_CreateMAC_Click(object sender, EventArgs e)
    {
        if (SingleMAC.Checked == true)
        {
            SaveFileDialog saveFileDialog;
            ST_EEPROM_MAC MacAddr;
            MacAddr.u8MacAdress = new Byte[6] { 0, 0, 0, 0, 0, 0 };
            Byte u8MacTotalVal = 0;
            Byte u8MacLen = 0;
            if (Byte1.Text == String.Empty || Byte2.Text == String.Empty || Byte3.Text == String.Empty || Byte4.Text == String.Empty || Byte5.Text == String.Empty || Byte6.Text == String.Empty)
            {
                MessageBox.Show("Input MAC Error!");
                return;
            }
            if (Convert.ToInt32(Byte1.Text, 16) > 255 || Convert.ToInt32(Byte2.Text, 16) > 255 ||
                Convert.ToInt32(Byte3.Text, 16) > 255 || Convert.ToInt32(Byte4.Text, 16) > 255 ||
                Convert.ToInt32(Byte5.Text, 16) > 255 || Convert.ToInt32(Byte6.Text, 16) > 255)
            {
                MessageBox.Show("Input MAC Error!");
                return;
            }
            {
                MacAddr.u8MacID0 = 0x55;
                MacAddr.u8MacID1 = 0xAA;
                MacAddr.u8MacID2 = 0x01;
                MacAddr.u8MacAdress[0] = Convert.ToByte(Convert.ToInt32(Byte1.Text, 16));
                MacAddr.u8MacAdress[1] = Convert.ToByte(Convert.ToInt32(Byte2.Text, 16));
                MacAddr.u8MacAdress[2] = Convert.ToByte(Convert.ToInt32(Byte3.Text, 16));
                MacAddr.u8MacAdress[3] = Convert.ToByte(Convert.ToInt32(Byte4.Text, 16));
                MacAddr.u8MacAdress[4] = Convert.ToByte(Convert.ToInt32(Byte5.Text, 16));
                MacAddr.u8MacAdress[5] = Convert.ToByte(Convert.ToInt32(Byte6.Text, 16));
                for (u8MacLen = 0; u8MacLen < 6; u8MacLen++)
                {
                    u8MacTotalVal = (Byte)(u8MacTotalVal + MacAddr.u8MacAdress[u8MacLen]);
                }
                u8MacTotalVal = (Byte)(0x100 - u8MacTotalVal);
                MacAddr.u8MacChecksum = u8MacTotalVal;
                saveFileDialog = new SaveFileDialog();
                saveFileDialog.Filter = "bin files(*.bin)|*.bin";
                saveFileDialog.FilterIndex = 2;
                saveFileDialog.RestoreDirectory = true; //保存对话框是否记忆上次打开的目录
                //saveFileDialog.CreatePrompt = true;
                saveFileDialog.Title = "导出MAC地址到";
               // DateTime now = DateTime.Now;
                saveFileDialog.FileName = "MACADDR.bin";
                //点了保存按钮进入
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    /*
                    if (saveFileDialog.FileName.Trim() == "")
                    {
                        MessageBox.Show("请输入要保存的文件名", "提示");
                        return;
                    }
                    progressBar.Visible = true; //进度条 ??
                    this.panel1.Enabled = false;
                     * */
                }
                else
                {
                   // MessageBox.Show("You cancel it!");
                    return;
                }
                try
                {
                    FileStream MACfile = new FileStream(saveFileDialog.FileName, FileMode.Create);
                    int MACAddr_Size = 10;// Marshal.SizeOf(MacAddr); //how to get the size
                    Byte[] WriteArray = new Byte[MACAddr_Size];
                    ChangMacToBtye(MacAddr, WriteArray);
                    /*
                    WriteArray[0] = MacAddr.u8MacID0;
                    WriteArray[1] = MacAddr.u8MacID1;
                    WriteArray[2] = MacAddr.u8MacID2;
                    WriteArray[3] = MacAddr.u8MacAdress[0];
                    WriteArray[4] = MacAddr.u8MacAdress[1];
                    WriteArray[5] = MacAddr.u8MacAdress[2];
                    WriteArray[6] = MacAddr.u8MacAdress[3];
                    WriteArray[7] = MacAddr.u8MacAdress[4];
                    WriteArray[8] = MacAddr.u8MacAdress[5];
                    WriteArray[9] = MacAddr.u8MacChecksum;*/
                    //以后再研究这种方式为什么会错!
                    // IntPtr StructPtr = Marshal.AllocHGlobal(MACAddr_Size);
                    // Marshal.StructureToPtr(MacAddr,StructPtr,false); //false this step data changed wrong
                    // Marshal.Copy(StructPtr,WriteArray,0,MACAddr_Size); //wrong
                    // Marshal.FreeHGlobal(StructPtr);
                    MACfile.Write(WriteArray, 0, MACAddr_Size);
                    MACfile.Flush();
                    MACfile.Close();
                    WriteLogFile(1,0);
                    MessageBox.Show("Crate MAC file success!");
                }
                catch
                {
                    MessageBox.Show("Execption happen!");
                }
            }
        }
            //sequential mode
        else if (SequentialMAC.Checked == true)
        {
            SaveFileDialog saveFileDialog;
            ST_EEPROM_MAC MacAddr;
            MacAddr.u8MacAdress = new Byte[6] { 0, 0, 0, 0, 0, 0 };
            Byte u8MacTotalVal = 0;
            Byte u8MacLen = 0;
            Byte[] TempMACAddr = new Byte[6];
            ulong StartMACToUlong = 0, EndMACToUlong = 0,MACCount = 0,Writetimes = 0;
            if (StartMACByte1.Text == String.Empty || StartMACByte2.Text == String.Empty || StartMACByte3.Text == String.Empty ||
                StartMACByte4.Text == String.Empty || StartMACByte5.Text == String.Empty || StartMACByte6.Text == String.Empty)
            {
                MessageBox.Show("Input Start MAC Error!");
                return;
            }
            if (Convert.ToInt32(StartMACByte1.Text, 16) > 255 || Convert.ToInt32(StartMACByte2.Text, 16) > 255 ||
                Convert.ToInt32(StartMACByte3.Text, 16) > 255 || Convert.ToInt32(StartMACByte4.Text, 16) > 255 ||
                Convert.ToInt32(StartMACByte5.Text, 16) > 255 || Convert.ToInt32(StartMACByte6.Text, 16) > 255)
            {
                MessageBox.Show("Input Start MAC Error!");
                return;
            }
            if (textBox_MACCount.Text == String.Empty)
            {
                MessageBox.Show("Please input the MAC Number!");
                return;
            }
            /*
            if (EndMACByte1.Text == String.Empty || EndMACByte2.Text == String.Empty || EndMACByte3.Text == String.Empty ||
                EndMACByte4.Text == String.Empty || EndMACByte5.Text == String.Empty || EndMACByte6.Text == String.Empty)
            {
                MessageBox.Show("Input End MAC Error!");
                return;
            }
            if (Convert.ToInt32(EndMACByte1.Text, 16) > 255 || Convert.ToInt32(EndMACByte2.Text, 16) > 255 ||
                Convert.ToInt32(EndMACByte3.Text, 16) > 255 || Convert.ToInt32(EndMACByte4.Text, 16) > 255 ||
                Convert.ToInt32(EndMACByte5.Text, 16) > 255 || Convert.ToInt32(EndMACByte6.Text, 16) > 255)
            {
                MessageBox.Show("Input End MAC Error!");
                return;
            }
             * */
            //get the end MAC
            /* //before create bin file depend on start MAC and End MAC
            TempMACAddr[0] = Convert.ToByte(Convert.ToInt32(EndMACByte1.Text, 16));
            TempMACAddr[1] = Convert.ToByte(Convert.ToInt32(EndMACByte2.Text, 16));
            TempMACAddr[2] = Convert.ToByte(Convert.ToInt32(EndMACByte3.Text, 16));
            TempMACAddr[3] = Convert.ToByte(Convert.ToInt32(EndMACByte4.Text, 16));
            TempMACAddr[4] = Convert.ToByte(Convert.ToInt32(EndMACByte5.Text, 16));
            TempMACAddr[5] = Convert.ToByte(Convert.ToInt32(EndMACByte6.Text, 16));
            EndMACToUlong = Convert.ToUInt64(TempMACAddr[3]) * 256 * 256 + Convert.ToUInt64(TempMACAddr[4]) * 256 + Convert.ToUInt64(TempMACAddr[5]);
            */
            //get the start MAC
            TempMACAddr[0] = Convert.ToByte(Convert.ToInt32(StartMACByte1.Text, 16));
            TempMACAddr[1] = Convert.ToByte(Convert.ToInt32(StartMACByte2.Text, 16));
            TempMACAddr[2] = Convert.ToByte(Convert.ToInt32(StartMACByte3.Text, 16));
            TempMACAddr[3] = Convert.ToByte(Convert.ToInt32(StartMACByte4.Text, 16));
            TempMACAddr[4] = Convert.ToByte(Convert.ToInt32(StartMACByte5.Text, 16));
            TempMACAddr[5] = Convert.ToByte(Convert.ToInt32(StartMACByte6.Text, 16));
            StartMACToUlong = Convert.ToUInt64(TempMACAddr[3]) * 256 * 256 + Convert.ToUInt64(TempMACAddr[4]) * 256 + Convert.ToUInt64(TempMACAddr[5]);
           
            //make sure the end mac is bigger than start mac
            /*
            if (EndMACToUlong<=StartMACToUlong)
            {
                MessageBox.Show("Please make sure End MAC is bigger than Start MAC");
                return;
            }
             * */
           //get MAC number
            /*
            MACCount = EndMACToUlong - StartMACToUlong+1;
            textBox_MACCount.Text = "You have create "+MACCount.ToString()+" MAC address";
             * */
            MACCount = Convert.ToUInt64(textBox_MACCount.Text);
            //show the end MAC
            EndMACToUlong = StartMACToUlong + MACCount-1;
            TempMACAddr[3] = Convert.ToByte(EndMACToUlong / 256 / 256);
            TempMACAddr[4] = Convert.ToByte((EndMACToUlong - Convert.ToUInt64(TempMACAddr[3]) * 256 * 256) / 256);
            TempMACAddr[5] = Convert.ToByte(EndMACToUlong % 256);
            EndMACByte1.Text = TempMACAddr[0].ToString("X2");
            EndMACByte2.Text = TempMACAddr[1].ToString("X2");
            EndMACByte3.Text = TempMACAddr[2].ToString("X2");
            EndMACByte4.Text = TempMACAddr[3].ToString("X2");
            EndMACByte5.Text = TempMACAddr[4].ToString("X2");
            EndMACByte6.Text = TempMACAddr[5].ToString("X2");
           
            saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "bin files(*.bin)|*.bin";
            saveFileDialog.FilterIndex = 2;
            saveFileDialog.RestoreDirectory = true; //保存对话框是否记忆上次打开的目录
            //saveFileDialog.CreatePrompt = true;
            saveFileDialog.Title = "导出MAC地址到";
            DateTime now = DateTime.Now;
            saveFileDialog.FileName = "MACADDR.bin";
            //点了保存按钮进入
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                /*
                if (saveFileDialog.FileName.Trim() == "")
                {
                    MessageBox.Show("请输入要保存的文件名", "提示");
                    return;
                }
                 * */
            }
            else
            {
                return;
            }
            try
            {
                int MACAddr_Size = 10;// use Marshal.SizeOf(MacAddr); get the size is wrong //how to get the size
                Byte[] WriteArray = new Byte[MACAddr_Size];
                FileStream MACfile = new FileStream(saveFileDialog.FileName, FileMode.Create);
                //将MAC地址写入到Bin文件中
                for (Writetimes = 0; Writetimes < MACCount; Writetimes++)
                {
                    MacAddr.u8MacID0 = 0x55;
                    MacAddr.u8MacID1 = 0xAA;
                    MacAddr.u8MacID2 = 0x01;
                    MacAddr.u8MacAdress[0] = TempMACAddr[0];
                    MacAddr.u8MacAdress[1] = TempMACAddr[1];
                    MacAddr.u8MacAdress[2] = TempMACAddr[2];
                    MacAddr.u8MacAdress[3] = Convert.ToByte(StartMACToUlong/256/256);
                    MacAddr.u8MacAdress[4] = Convert.ToByte((StartMACToUlong - Convert.ToUInt64(MacAddr.u8MacAdress[3]) * 256 * 256) / 256);
                    MacAddr.u8MacAdress[5] = Convert.ToByte(StartMACToUlong%256);
                    for (u8MacLen = 0; u8MacLen < 6; u8MacLen++)
                    {
                        u8MacTotalVal = (Byte)(u8MacTotalVal + MacAddr.u8MacAdress[u8MacLen]);
                    }
                    u8MacTotalVal = (Byte)(0x100 - u8MacTotalVal);
                    MacAddr.u8MacChecksum = u8MacTotalVal;
                    ChangMacToBtye(MacAddr, WriteArray);
                    MACfile.Write(WriteArray, 0,MACAddr_Size);
                    StartMACToUlong++;
                }
                MACfile.Flush();
                MACfile.Close();
                WriteLogFile(MACCount,1);
                MessageBox.Show("Create MAC success");
            }
            catch
            {
                MessageBox.Show("Execption happen!");
            }
        }
        else
        {
            MessageBox.Show("Please choose a mode!");
        }
    }
    private void Byte1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar == 8) || ((e.KeyChar > 47) && (e.KeyChar < 58))
            || ((e.KeyChar > 64) && (e.KeyChar < 71)) || ((e.KeyChar > 96) && (e.KeyChar < 103)))
        {
            //
        }
        else
        {
          // MessageBox.Show("Wrong input!");
            e.Handled = true;
        }
    }
    private void Byte2_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar == 8) || ((e.KeyChar > 47) && (e.KeyChar < 58))
            || ((e.KeyChar > 64) && (e.KeyChar < 71)) || ((e.KeyChar > 96) && (e.KeyChar < 103)))
        {
            //
        }
        else
        {
            // MessageBox.Show("Wrong input!");
            e.Handled = true;
        }
    }
    private void Byte3_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar == 8) || ((e.KeyChar > 47) && (e.KeyChar < 58))
            || ((e.KeyChar > 64) && (e.KeyChar < 71)) || ((e.KeyChar > 96) && (e.KeyChar < 103)))
        {
            //
        }
        else
        {
            // MessageBox.Show("Wrong input!");
            e.Handled = true;
        }
    }
    private void Byte4_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar == 8) || ((e.KeyChar > 47) && (e.KeyChar < 58))
         || ((e.KeyChar > 64) && (e.KeyChar < 71)) || ((e.KeyChar > 96) && (e.KeyChar < 103)))
        {
            //
        }
        else
        {
            // MessageBox.Show("Wrong input!");
            e.Handled = true;
        }
    }
    private void Byte5_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar == 8) || ((e.KeyChar > 47) && (e.KeyChar < 58))
            || ((e.KeyChar > 64) && (e.KeyChar < 71)) || ((e.KeyChar > 96) && (e.KeyChar < 103)))
        {
            //
        }
        else
        {
            // MessageBox.Show("Wrong input!");
            e.Handled = true;
        }
    }
    private void Byte6_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar == 8) || ((e.KeyChar > 47) && (e.KeyChar < 58))
            || ((e.KeyChar > 64) && (e.KeyChar < 71)) || ((e.KeyChar > 96) && (e.KeyChar < 103)))
        {
            //
        }
        else
        {
            // MessageBox.Show("Wrong input!");
            e.Handled = true;
        }
    }
    private void textBox1_TextChanged(object sender, EventArgs e)
    {
    }
    private void StartMACByte6_TextChanged(object sender, EventArgs e)
    {
    }
    private void StartMACByte5_TextChanged(object sender, EventArgs e)
    {
    }
    private void StartMACByte4_TextChanged(object sender, EventArgs e)
    {
    }
    private void Byte6_TextChanged(object sender, EventArgs e)
    {
    }
    private void SingleMAC_CheckedChanged(object sender, EventArgs e)
    {
        if (SingleMAC.Checked == true)
        {
            if (SequentialMAC.Checked == true)
            {
                MessageBox.Show("You have choosed the sequential mode!");
                SingleMAC.Checked = false;
            }
        }
    }
    private void SequentialMAC_CheckedChanged(object sender, EventArgs e)
    {
        if (SequentialMAC.Checked == true)
        {
            if (SingleMAC.Checked == true)
            {
                MessageBox.Show("You have choosed the single mode!");
                SequentialMAC.Checked = false;
            }
        }
    }
    private void SingleMAC_CheckStateChanged(object sender, EventArgs e)
    {
    }
    private void Byte3_TextChanged(object sender, EventArgs e)
    {
    }
    private void StartMACByte1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar == 8) || ((e.KeyChar > 47) && (e.KeyChar < 58))
            || ((e.KeyChar > 64) && (e.KeyChar < 71)) || ((e.KeyChar > 96) && (e.KeyChar < 103)))
        {
            //
        }
        else
        {
            // MessageBox.Show("Wrong input!");
            e.Handled = true;
        }
    }
    private void StartMACByte2_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar == 8) || ((e.KeyChar > 47) && (e.KeyChar < 58))
            || ((e.KeyChar > 64) && (e.KeyChar < 71)) || ((e.KeyChar > 96) && (e.KeyChar < 103)))
        {
            //
        }
        else
        {
            // MessageBox.Show("Wrong input!");
            e.Handled = true;
        }
    }
    private void StartMACByte3_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar == 8) || ((e.KeyChar > 47) && (e.KeyChar < 58))
            || ((e.KeyChar > 64) && (e.KeyChar < 71)) || ((e.KeyChar > 96) && (e.KeyChar < 103)))
        {
            //
        }
        else
        {
            // MessageBox.Show("Wrong input!");
            e.Handled = true;
        }
    }
    private void StartMACByte4_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar == 8) || ((e.KeyChar > 47) && (e.KeyChar < 58))
             || ((e.KeyChar > 64) && (e.KeyChar < 71)) || ((e.KeyChar > 96) && (e.KeyChar < 103)))
        {
            //
        }
        else
        {
            // MessageBox.Show("Wrong input!");
            e.Handled = true;
        }
    }
    private void StartMACByte5_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar == 8) || ((e.KeyChar > 47) && (e.KeyChar < 58))
            || ((e.KeyChar > 64) && (e.KeyChar < 71)) || ((e.KeyChar > 96) && (e.KeyChar < 103)))
        {
            //
        }
        else
        {
            // MessageBox.Show("Wrong input!");
            e.Handled = true;
        }
    }
    private void StartMACByte6_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar == 8) || ((e.KeyChar > 47) && (e.KeyChar < 58))
            || ((e.KeyChar > 64) && (e.KeyChar < 71)) || ((e.KeyChar > 96) && (e.KeyChar < 103)))
        {
            //
        }
        else
        {
            // MessageBox.Show("Wrong input!");
            e.Handled = true;
        }
    }
    private void EndMACByte1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar == 8) || ((e.KeyChar > 47) && (e.KeyChar < 58))
            || ((e.KeyChar > 64) && (e.KeyChar < 71)) || ((e.KeyChar > 96) && (e.KeyChar < 103)))
        {
            //
        }
        else
        {
            // MessageBox.Show("Wrong input!");
            e.Handled = true;
        }
    }
    private void EndMACByte2_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar == 8) || ((e.KeyChar > 47) && (e.KeyChar < 58))
            || ((e.KeyChar > 64) && (e.KeyChar < 71)) || ((e.KeyChar > 96) && (e.KeyChar < 103)))
        {
            //
        }
        else
        {
            // MessageBox.Show("Wrong input!");
            e.Handled = true;
        }
    }
    private void EndMACByte3_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar == 8) || ((e.KeyChar > 47) && (e.KeyChar < 58))
            || ((e.KeyChar > 64) && (e.KeyChar < 71)) || ((e.KeyChar > 96) && (e.KeyChar < 103)))
        {
            //
        }
        else
        {
            // MessageBox.Show("Wrong input!");
            e.Handled = true;
        }
    }
    private void EndMACByte4_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar == 8) || ((e.KeyChar > 47) && (e.KeyChar < 58))
            || ((e.KeyChar > 64) && (e.KeyChar < 71)) || ((e.KeyChar > 96) && (e.KeyChar < 103)))
        {
            //
        }
        else
        {
            // MessageBox.Show("Wrong input!");
            e.Handled = true;
        }
    }
    private void EndMACByte5_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar == 8) || ((e.KeyChar > 47) && (e.KeyChar < 58))
            || ((e.KeyChar > 64) && (e.KeyChar < 71)) || ((e.KeyChar > 96) && (e.KeyChar < 103)))
        {
            //
        }
        else
        {
            // MessageBox.Show("Wrong input!");
            e.Handled = true;
        }
    }
    private void EndMACByte6_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar == 8) || ((e.KeyChar > 47) && (e.KeyChar < 58))
            || ((e.KeyChar > 64) && (e.KeyChar < 71)) || ((e.KeyChar > 96) && (e.KeyChar < 103)))
        {
            //
        }
        else
        {
            // MessageBox.Show("Wrong input!");
            e.Handled = true;
        }
    }
    private void textBox_MACCount_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((e.KeyChar == 8) || ((e.KeyChar > 47) && (e.KeyChar < 58)))
        {
            //
        }
        else
        {
            // MessageBox.Show("Wrong input!");
            e.Handled = true;
        }
    }
    private void EndMACByte1_TextChanged(object sender, EventArgs e)
    {
        if (EndMACByte1.Text != StartMACByte1.Text)
        {
            MessageBox.Show("Must be same with the start MAC");
            EndMACByte1.Text = StartMACByte1.Text;
        }
    }
    private void EndMACByte2_TextChanged(object sender, EventArgs e)
    {
        if (EndMACByte2.Text != StartMACByte2.Text)
        {
            MessageBox.Show("Must be same with the start MAC");
            EndMACByte2.Text = StartMACByte2.Text;
        }
    }
    private void EndMACByte3_TextChanged(object sender, EventArgs e)
    {
        if (EndMACByte3.Text != StartMACByte3.Text)
        {
            MessageBox.Show("Must be same with the start MAC");
            EndMACByte3.Text = StartMACByte3.Text;
        }
    }
    private void StartMACByte1_TextChanged(object sender, EventArgs e)
    {
        EndMACByte1.Text = StartMACByte1.Text;
    }
    private void StartMACByte2_TextChanged(object sender, EventArgs e)
    {
        EndMACByte2.Text = StartMACByte2.Text;
    }
    private void StartMACByte3_TextChanged(object sender, EventArgs e)
    {
        EndMACByte3.Text = StartMACByte3.Text;
    }

}

}

猜你喜欢

转载自blog.csdn.net/yikezhuixun/article/details/131623920