C#制作IP地址切换的源程序代码.docx

上传人:b****5 文档编号:6409632 上传时间:2023-01-06 格式:DOCX 页数:23 大小:21.66KB
下载 相关 举报
C#制作IP地址切换的源程序代码.docx_第1页
第1页 / 共23页
C#制作IP地址切换的源程序代码.docx_第2页
第2页 / 共23页
C#制作IP地址切换的源程序代码.docx_第3页
第3页 / 共23页
C#制作IP地址切换的源程序代码.docx_第4页
第4页 / 共23页
C#制作IP地址切换的源程序代码.docx_第5页
第5页 / 共23页
点击查看更多>>
下载资源
资源描述

C#制作IP地址切换的源程序代码.docx

《C#制作IP地址切换的源程序代码.docx》由会员分享,可在线阅读,更多相关《C#制作IP地址切换的源程序代码.docx(23页珍藏版)》请在冰豆网上搜索。

C#制作IP地址切换的源程序代码.docx

C#制作IP地址切换的源程序代码

C#制作IP地址切换的源程序代码

1.启动代码:

1

2.主界面设计器代码:

1

3.主界面程序代码:

7

4.Xml文件操作代码:

14

1.启动代码:

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Windows.Forms;

namespaceIpChange

{

staticclassProgram

{

///

///应用程序的主入口点。

///

[STAThread]

staticvoidMain()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(newForm1());

}

}

}

2.主界面设计器代码:

namespaceIpChange

{

partialclassForm1

{

///

///必需的设计器变量。

///

privateSystem.ComponentModel.IContainercomponents=null;

///

///清理所有正在使用的资源。

///

///如果应释放托管资源,为true;否则为false。

protectedoverridevoidDispose(booldisposing)

{

if(disposing&&(components!

=null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#regionWindows窗体设计器生成的代码

///

///设计器支持所需的方法-不要

///使用代码编辑器修改此方法的内容。

///

privatevoidInitializeComponent()

{

this.pnlNetworkInfo=newSystem.Windows.Forms.Panel();

this.dgvNetwork=newSystem.Windows.Forms.DataGridView();

this.panel1=newSystem.Windows.Forms.Panel();

this.btnSetIP=newSystem.Windows.Forms.Button();

this.label1=newSystem.Windows.Forms.Label();

this.btnSaveLocal=newSystem.Windows.Forms.Button();

this.pnlIpInfo=newSystem.Windows.Forms.Panel();

this.dgvLocalXml=newSystem.Windows.Forms.DataGridView();

this.panel2=newSystem.Windows.Forms.Panel();

this.label3=newSystem.Windows.Forms.Label();

this.txtLocalIpName=newSystem.Windows.Forms.TextBox();

this.label2=newSystem.Windows.Forms.Label();

this.pnlNetworkInfo.SuspendLayout();

((System.ComponentModel.ISupportInitialize)(this.dgvNetwork)).BeginInit();

this.panel1.SuspendLayout();

this.pnlIpInfo.SuspendLayout();

((System.ComponentModel.ISupportInitialize)(this.dgvLocalXml)).BeginInit();

this.panel2.SuspendLayout();

this.SuspendLayout();

//

//pnlNetworkInfo

//

this.pnlNetworkInfo.Controls.Add(this.dgvNetwork);

this.pnlNetworkInfo.Controls.Add(this.panel1);

this.pnlNetworkInfo.Dock=System.Windows.Forms.DockStyle.Top;

this.pnlNetworkInfo.Location=newSystem.Drawing.Point(0,0);

this.pnlNetworkInfo.Name="pnlNetworkInfo";

this.pnlNetworkInfo.Size=newSystem.Drawing.Size(572,157);

this.pnlNetworkInfo.TabIndex=0;

//

//dgvNetwork

//

this.dgvNetwork.AllowUserToAddRows=false;

this.dgvNetwork.AllowUserToDeleteRows=false;

this.dgvNetwork.AutoSizeColumnsMode=System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells;

this.dgvNetwork.BackgroundColor=System.Drawing.SystemColors.Control;

this.dgvNetwork.ColumnHeadersHeightSizeMode=System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;

this.dgvNetwork.Dock=System.Windows.Forms.DockStyle.Fill;

this.dgvNetwork.Location=newSystem.Drawing.Point(0,30);

this.dgvNetwork.Name="dgvNetwork";

this.dgvNetwork.ReadOnly=true;

this.dgvNetwork.RowTemplate.Height=23;

this.dgvNetwork.Size=newSystem.Drawing.Size(572,127);

this.dgvNetwork.TabIndex=1;

this.dgvNetwork.MouseClick+=newSystem.Windows.Forms.MouseEventHandler(this.dgvNetwork_MouseClick);

//

//panel1

//

this.panel1.BorderStyle=System.Windows.Forms.BorderStyle.FixedSingle;

this.panel1.Controls.Add(this.btnSetIP);

this.panel1.Controls.Add(this.label1);

this.panel1.Dock=System.Windows.Forms.DockStyle.Top;

this.panel1.Location=newSystem.Drawing.Point(0,0);

this.panel1.Name="panel1";

this.panel1.Size=newSystem.Drawing.Size(572,30);

this.panel1.TabIndex=0;

//

//btnSetIP

//

this.btnSetIP.Location=newSystem.Drawing.Point(437,4);

this.btnSetIP.Name="btnSetIP";

this.btnSetIP.Size=newSystem.Drawing.Size(111,23);

this.btnSetIP.TabIndex=2;

this.btnSetIP.Text="使用备用IP信息";

this.btnSetIP.UseVisualStyleBackColor=true;

this.btnSetIP.Click+=newSystem.EventHandler(this.btnSetIP_Click);

//

//label1

//

this.label1.AutoSize=true;

this.label1.Location=newSystem.Drawing.Point(12,9);

this.label1.Name="label1";

this.label1.Size=newSystem.Drawing.Size(65,12);

this.label1.TabIndex=0;

this.label1.Text="网卡信息:

";

//

//btnSaveLocal

//

this.btnSaveLocal.Location=newSystem.Drawing.Point(437,3);

this.btnSaveLocal.Name="btnSaveLocal";

this.btnSaveLocal.Size=newSystem.Drawing.Size(111,23);

this.btnSaveLocal.TabIndex=1;

this.btnSaveLocal.Text="IP信息保存到备用";

this.btnSaveLocal.UseVisualStyleBackColor=true;

this.btnSaveLocal.Click+=newSystem.EventHandler(this.btnSaveLocal_Click);

//

//pnlIpInfo

//

this.pnlIpInfo.Controls.Add(this.dgvLocalXml);

this.pnlIpInfo.Controls.Add(this.panel2);

this.pnlIpInfo.Dock=System.Windows.Forms.DockStyle.Fill;

this.pnlIpInfo.Location=newSystem.Drawing.Point(0,157);

this.pnlIpInfo.Name="pnlIpInfo";

this.pnlIpInfo.Size=newSystem.Drawing.Size(572,281);

this.pnlIpInfo.TabIndex=1;

//

//dgvLocalXml

//

this.dgvLocalXml.AllowUserToAddRows=false;

this.dgvLocalXml.AllowUserToDeleteRows=false;

this.dgvLocalXml.AutoSizeColumnsMode=System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells;

this.dgvLocalXml.BackgroundColor=System.Drawing.SystemColors.Control;

this.dgvLocalXml.ColumnHeadersHeightSizeMode=System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;

this.dgvLocalXml.Dock=System.Windows.Forms.DockStyle.Fill;

this.dgvLocalXml.Location=newSystem.Drawing.Point(0,29);

this.dgvLocalXml.Name="dgvLocalXml";

this.dgvLocalXml.ReadOnly=true;

this.dgvLocalXml.RowTemplate.Height=23;

this.dgvLocalXml.Size=newSystem.Drawing.Size(572,252);

this.dgvLocalXml.TabIndex=2;

this.dgvLocalXml.MouseClick+=newSystem.Windows.Forms.MouseEventHandler(this.dgvLocalXml_MouseClick);

//

//panel2

//

this.panel2.BorderStyle=System.Windows.Forms.BorderStyle.FixedSingle;

this.panel2.Controls.Add(this.label3);

this.panel2.Controls.Add(this.txtLocalIpName);

this.panel2.Controls.Add(this.label2);

this.panel2.Controls.Add(this.btnSaveLocal);

this.panel2.Dock=System.Windows.Forms.DockStyle.Top;

this.panel2.Location=newSystem.Drawing.Point(0,0);

this.panel2.Name="panel2";

this.panel2.Size=newSystem.Drawing.Size(572,29);

this.panel2.TabIndex=3;

//

//label3

//

this.label3.AutoSize=true;

this.label3.Location=newSystem.Drawing.Point(269,8);

this.label3.Name="label3";

this.label3.Size=newSystem.Drawing.Size(41,12);

this.label3.TabIndex=3;

this.label3.Text="名称:

";

//

//txtLocalIpName

//

this.txtLocalIpName.Location=newSystem.Drawing.Point(311,5);

this.txtLocalIpName.Name="txtLocalIpName";

this.txtLocalIpName.Size=newSystem.Drawing.Size(100,21);

this.txtLocalIpName.TabIndex=2;

//

//label2

//

this.label2.AutoSize=true;

this.label2.Location=newSystem.Drawing.Point(12,8);

this.label2.Name="label2";

this.label2.Size=newSystem.Drawing.Size(77,12);

this.label2.TabIndex=1;

this.label2.Text="备用IP信息:

";

//

//Form1

//

this.AutoScaleDimensions=newSystem.Drawing.SizeF(6F,12F);

this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;

this.ClientSize=newSystem.Drawing.Size(572,438);

this.Controls.Add(this.pnlIpInfo);

this.Controls.Add(this.pnlNetworkInfo);

this.MaximizeBox=false;

this.Name="Form1";

this.StartPosition=System.Windows.Forms.FormStartPosition.CenterScreen;

this.Text="IPChange";

this.pnlNetworkInfo.ResumeLayout(false);

((System.ComponentModel.ISupportInitialize)(this.dgvNetwork)).EndInit();

this.panel1.ResumeLayout(false);

this.panel1.PerformLayout();

this.pnlIpInfo.ResumeLayout(false);

((System.ComponentModel.ISupportInitialize)(this.dgvLocalXml)).EndInit();

this.panel2.ResumeLayout(false);

this.panel2.PerformLayout();

this.ResumeLayout(false);

}

#endregion

privateSystem.Windows.Forms.PanelpnlNetworkInfo;

privateSystem.Windows.Forms.PanelpnlIpInfo;

privateSystem.Windows.Forms.Panelpanel1;

privateSystem.Windows.Forms.Labellabel1;

privateSystem.Windows.Forms.DataGridViewdgvNetwork;

privateSystem.Windows.Forms.ButtonbtnSaveLocal;

privateSystem.Windows.Forms.ButtonbtnSetIP;

privateSystem.Windows.Forms.DataGridViewdgvLocalXml;

privateSystem.Windows.Forms.Panelpanel2;

privateSystem.Windows.Forms.Labellabel2;

privateSystem.Windows.Forms.Labellabel3;

privateSystem.Windows.Forms.TextBoxtxtLocalIpName;

}

}

3.主界面程序代码:

usingSystem;

usingSystem.Collections;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Text;

usingSystem.Windows.Forms;

usingSystem.Net;

usingSystem.Management;

usingSystem.IO;

namespaceIpChange

{

publicpartialclassForm1:

Form

{

publicForm1()

{

InitializeComponent();

if(Init()<1)

{

MessageBox.Show("未找到网卡!

");

}

}

///

///网卡信息

///

privateDataTable_dtNetwork;

///

///选中的网卡信息

///

privateDataRow_drNetworkSelected;

///

///选中的本地配置信息

///

privateDataRow_drLocalIPSelected;

privatestring_strXmlPath=string.Format(@"{0}\config.xml",Application.StartupPath);

///

///生成Xml配置文件

///

///配置文件路径

///1添加2修改3删除

///IP信息

///IP名称

privatevoidConfigXmlOper(stringstrPath,intiType,DataRowdr,stringstrIpName)

{

XmlHelperxmls=newXmlHelper(this._strXmlPath);

if(!

File.Exists(strPath))

{

xmls.CreateXmlRoot("IPInfo",true,true);

}

if(dr!

=null)

{

//生成属性键值集合

DictionarydXml;

stringstrChildNoteName="Note

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1