如何把ini文件转换为xml
作者:- 来源:www.csdn.net 添加时间:2006-5-21 9:53:02frmMain.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Loki
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmMain : System.Windows.Forms.Form
{
public System.Windows.Forms.Button btnConvert;
public System.Windows.Forms.TextBox txtXMLFileName;
public System.Windows.Forms.Label Label2;
public System.Windows.Forms.TextBox txtIniFileName;
public System.Windows.Forms.Button btnClose;
public System.Windows.Forms.Label Label1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public frmMain()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnConvert = new System.Windows.Forms.Button();
this.txtXMLFileName = new System.Windows.Forms.TextBox();
this.txtIniFileName = new System.Windows.Forms.TextBox();
this.Label1 = new System.Windows.Forms.Label();
this.btnClose = new System.Windows.Forms.Button();
this.Label2 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// btnConvert
//
this.btnConvert.BackColor = System.Drawing.SystemColors.Control;
this.btnConvert.Cursor = System.Windows.Forms.Cursors.Default;
this.btnConvert.Location = new System.Drawing.Point(160, 96);
this.btnConvert.Name = "btnConvert";
this.btnConvert.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.btnConvert.Size = new System.Drawing.Size(105, 25);
this.btnConvert.TabIndex = 4;
this.btnConvert.Text = "&Convert";
this.btnConvert.Click += new System.EventHandler(this.btnConvert_Click);
//
// txtXMLFileName
//
this.txtXMLFileName.AcceptsReturn = true;
this.txtXMLFileName.AutoSize = false;
this.txtXMLFileName.BackColor = System.Drawing.SystemColors.Window;
this.txtXMLFileName.Cursor = System.Windows.Forms.Cursors.IBeam;
this.txtXMLFileName.ForeColor = System.Drawing.SystemColors.WindowText;
this.txtXMLFileName.Location = new System.Drawing.Point(104, 48);
this.txtXMLFileName.MaxLength = 0;
this.txtXMLFileName.Name = "txtXMLFileName";
this.txtXMLFileName.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.txtXMLFileName.Size = new System.Drawing.Size(273, 25);
this.txtXMLFileName.TabIndex = 3;
this.txtXMLFileName.Text = "";
//
// txtIniFileName
//
this.txtIniFileName.AcceptsReturn = true;
this.txtIniFileName.AutoSize = false;
this.txtIniFileName.BackColor = System.Drawing.SystemColors.Window;
this.txtIniFileName.Cursor = System.Windows.Forms.Cursors.IBeam;
this.txtIniFileName.ForeColor = System.Drawing.SystemColors.WindowText;
this.txtIniFileName.Location = new System.Drawing.Point(104, 16);
this.txtIniFileName.MaxLength = 0;
this.txtIniFileName.Name = "txtIniFileName";
this.txtIniFileName.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.txtIniFileName.Size = new System.Drawing.Size(273, 25);
this.txtIniFileName.TabIndex = 1;
this.txtIniFileName.Text = "E:\\Source\\Loki\\INI2XML\\VB.NET\\projINI2XML.NET\\Sample.ini";
//
// Label1
//
this.Label1.AutoSize = true;
this.Label1.BackColor = System.Drawing.SystemColors.Control;
this.Label1.Cursor = System.Windows.Forms.Cursors.Default;
this.Label1.ForeColor = System.Drawing.SystemColors.ControlText;
this.Label1.Location = new System.Drawing.Point(16, 24);
this.Label1.Name = "Label1";
this.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.Label1.Size = new System.Drawing.Size(68, 13);
this.Label1.TabIndex = 0;
this.Label1.Text = "INI Filename";
//
// btnClose
//
this.btnClose.BackColor = System.Drawing.SystemColors.Control;
this.btnClose.Cursor = System.Windows.Forms.Cursors.Default;
this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnClose.Location = new System.Drawing.Point(272, 96);
this.btnClose.Name = "btnClose";
this.btnClose.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.btnClose.Size = new System.Drawing.Size(105, 25);
this.btnClose.TabIndex = 5;
this.btnClose.Text = "Close";
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// Label2
//
this.Label2.AutoSize = true;
this.Label2.BackColor = System.Drawing.SystemColors.Control;
this.Label2.Cursor = System.Windows.Forms.Cursors.Default;
this.Label2.ForeColor = System.Drawing.SystemColors.ControlText;
this.Label2.Location = new System.Drawing.Point(16, 56);
this.Label2.Name = "Label2";
this.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.Label2.Size = new System.Drawing.Size(77, 13);
this.Label2.TabIndex = 2;
this.Label2.Text = "XML Filename";
//
// frmMain
//
this.AcceptButton = this.btnConvert;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.btnClose;
this.ClientSize = new System.Drawing.Size(392, 141);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnConvert,
this.txtXMLFileName,
this.Label2,
this.txtIniFileName,
this.btnClose,
this.Label1});
this.Name = "frmMain";
this.Text = "INI 2 XML";
this.Load += new System.EventHandler(this.frmMain_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmMain());
}
private void frmMain_Load(object sender, System.EventArgs e)
{
}
private void btnConvert_Click(object sender, System.EventArgs e)
{
if (INI2XML.Convert( txtIniFileName.Text, txtXMLFileName.Text ))
System.Windows.Forms.MessageBox.Show( "Successfully converted \"" + txtIniFileName.Text + "\" to \"" + txtXMLFileName.Text + "\"", this.Text, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information );
else
System.Windows.Forms.MessageBox.Show( "Problem converting \"" + txtIniFileName.Text + "\" to \"" + txtXMLFileName.Text + "\"", this.Text, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation );
}
private void btnClose_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
站内搜索