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 Microsoft.Win32;

namespace Ex09_3
{
    public partial class Form1 : Form
    {

        public string strnew ;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string[] str = new string[1];
            str[0] = this.textBox1.Text;
            string path = @"System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" + strnew;
            Registry.LocalMachine.CreateSubKey(path).SetValue("IPAddress", str, RegistryValueKind.MultiString);
            MessageBox.Show(this, "成功修改了本机IP地址！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            RegistryKey reg = Registry.LocalMachine.OpenSubKey(@"System\CurrentControlSet\Services\Tcpip\Linkage");
            string[] str = (String[])reg.GetValue("Route");
            strnew = str[0].Substring(1, str[0].Length - 2);
            string path = @"System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" + strnew;
            RegistryKey regIp = Registry.LocalMachine.OpenSubKey(path);
            string[] strIP = (String[])regIp.GetValue("IPAddress", "Null", RegistryValueOptions.None);
            textBox1.Text = strIP[0];
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
