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

📄 frmtest.cs

📁 不用api的ini,c#类,ce可用
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using cn.com.daway;

namespace ceIniFile
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class frmTest : System.Windows.Forms.Form
	{
		private System.Windows.Forms.MainMenu mainMenu1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox txtSection;
		private System.Windows.Forms.TextBox txtKey;
		private System.Windows.Forms.TextBox txtValue;
		private System.Windows.Forms.Button btnRead;
		private System.Windows.Forms.Button btnWrite;
		private System.Windows.Forms.Label label1;
		private IniConfig m_iniFile;

		public frmTest()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}
		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			base.Dispose( disposing );
		}
		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.txtSection = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.txtKey = new System.Windows.Forms.TextBox();
			this.txtValue = new System.Windows.Forms.TextBox();
			this.btnRead = new System.Windows.Forms.Button();
			this.btnWrite = new System.Windows.Forms.Button();
			// 
			// txtSection
			// 
			this.txtSection.Location = new System.Drawing.Point(72, 32);
			this.txtSection.Size = new System.Drawing.Size(128, 21);
			this.txtSection.Text = "test";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 32);
			this.label1.Size = new System.Drawing.Size(24, 20);
			this.label1.Text = "节";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 76);
			this.label2.Size = new System.Drawing.Size(24, 20);
			this.label2.Text = "键";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(16, 120);
			this.label3.Size = new System.Drawing.Size(24, 20);
			this.label3.Text = "值";
			// 
			// txtKey
			// 
			this.txtKey.Location = new System.Drawing.Point(72, 72);
			this.txtKey.Size = new System.Drawing.Size(128, 21);
			this.txtKey.Text = "test";
			// 
			// txtValue
			// 
			this.txtValue.Location = new System.Drawing.Point(72, 112);
			this.txtValue.Size = new System.Drawing.Size(128, 21);
			this.txtValue.Text = "";
			// 
			// btnRead
			// 
			this.btnRead.Location = new System.Drawing.Point(24, 184);
			this.btnRead.Size = new System.Drawing.Size(72, 24);
			this.btnRead.Text = "读取";
			this.btnRead.Click += new System.EventHandler(this.btnRead_Click);
			// 
			// btnWrite
			// 
			this.btnWrite.Location = new System.Drawing.Point(120, 184);
			this.btnWrite.Size = new System.Drawing.Size(72, 24);
			this.btnWrite.Text = "写入";
			this.btnWrite.Click += new System.EventHandler(this.btnWrite_Click);
			// 
			// frmTest
			// 
			this.Controls.Add(this.btnWrite);
			this.Controls.Add(this.btnRead);
			this.Controls.Add(this.txtValue);
			this.Controls.Add(this.txtKey);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.txtSection);
			this.MaximizeBox = false;
			this.Menu = this.mainMenu1;
			this.MinimizeBox = false;
			this.Text = "iniFile测试";
			this.Closed += new System.EventHandler(this.Form1_Closed);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>

		static void Main() 
		{
			Application.Run(new frmTest());
		}

		private void Form1_Closed(object sender, System.EventArgs e)
		{
			this.Dispose(true);
			Application.Exit();
		}

		private void btnRead_Click(object sender, System.EventArgs e)
		{
			m_iniFile=new IniConfig("test.ini");
			try
			{
				txtValue.Text=m_iniFile.GetProfileString(txtSection.Text.Trim(),txtKey.Text.Trim());
			}
			catch(Exception err)
			{
				MessageBox.Show(err.Message,"错误",MessageBoxButtons.OK,MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button1);
			}
			m_iniFile.Dispose();
		}

		private void btnWrite_Click(object sender, System.EventArgs e)
		{
			m_iniFile=new IniConfig("test.ini");
			try
			{
				m_iniFile.WriteProfileString(txtSection.Text.Trim(),txtKey.Text.Trim(),txtValue.Text.Trim());
				txtValue.Text="成功";
			}
			catch(Exception err)
			{
				MessageBox.Show(err.Message,"错误",MessageBoxButtons.OK,MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button1);
			}
			m_iniFile.Dispose();
		}
	}
}

⌨️ 快捷键说明

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