亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#操作INI配置文件示例詳解

 更新時間:2017年07月13日 11:41:41   作者:cnc  
這篇文章主要為大家詳細介紹了C#操作INI配置文件示例,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了C#操作INI配置文件示例的具體代碼,供大家參考,具體內容如下

源文件地址:C#操作INI配置文件示例

創(chuàng)建如圖所示的控件:

源代碼:

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.Runtime.InteropServices;

namespace WindowsFormsApplication3

{

  public partial class Form1 : Form

  {

    public Form1()

    {

      InitializeComponent();

    }

 

    [DllImport("kernel32.dll")]

    private static extern long WritePrivateProfileString(string section, string key, string value, string filepath);

 

    [DllImport("kernel32.dll")]

    private static extern int GetPrivateProfileString(string section,string key,string def,StringBuilder returnvalue,intbuffersize,string filepath);

 

    private string IniFilePath;
    private void Form1_Load(object sender, EventArgs e)

    {

      comboBox1.Text = "男";

      for (int i = 1; i <= 100; i++)

      {

        comboBox2.Items.Add(i.ToString());

      }

      comboBox2.Text = "18";

      IniFilePath = Application.StartupPath + "\\Config.ini";

    }

 

    private void button1_Click(object sender, EventArgs e)
    {
      if ((textBox1.Text.Trim() != "") && (textBox2.Text.Trim() != ""))
      {
        string Section = "Information";
        try

        {

          WritePrivateProfileString(Section, "Name", textBox1.Text.Trim(), IniFilePath);
          WritePrivateProfileString(Section, "Gender", comboBox1.Text, IniFilePath);
          WritePrivateProfileString(Section, "Age", comboBox2.Text, IniFilePath);
          WritePrivateProfileString(Section, "Region", textBox2.Text.Trim(), IniFilePath);

        }
        catch (Exception ee)

        {

          MessageBox.Show(ee.Message);

        }
      }

      else

      {

        MessageBox.Show("姓名或地區(qū)不能為空!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Warning);

      }
    }

 

    private void button2_Click(object sender, EventArgs e)
    {
      string outString;
      try

      {
        GetValue("Information", "Name", out outString);
        textBox1.Text = outString;
        GetValue("Information", "Gender", out outString);
        comboBox1.Text = outString;
        GetValue("Information", "Age", out outString);
        comboBox2.Text = outString;
        GetValue("Information", "Region", out outString);
        textBox2.Text = outString;

      }

      catch (Exception ee)

      {

        MessageBox.Show(ee.Message);

      }

 

    }

 

    private void GetValue(string section,string key, out string value)
    {

      StringBuilder stringBuilder = new StringBuilder();
      GetPrivateProfileString(section, key, "", stringBuilder, 1024, IniFilePath);
      value = stringBuilder.ToString();

    }

 

    private void button3_Click(object sender, EventArgs e)

    {
      textBox1.Text = "";
      comboBox1.Text = "男";
      comboBox2.Text = "18";
      textBox2.Text = "";
    }

  }

} 

 運行結果:

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • 支持多類型數(shù)據(jù)庫的c#數(shù)據(jù)庫模型示例

    支持多類型數(shù)據(jù)庫的c#數(shù)據(jù)庫模型示例

    本文為大家提供一個c#數(shù)據(jù)庫訪問模型,支持多類型數(shù)據(jù)庫,簡單抽取數(shù)據(jù)庫訪問函數(shù),大家參考使用吧
    2014-01-01
  • C#實現(xiàn)洗牌游戲實例

    C#實現(xiàn)洗牌游戲實例

    這篇文章主要介紹了C#實現(xiàn)洗牌游戲實例,對于數(shù)據(jù)結構與算法的學習有不錯的借鑒參考作用,需要的朋友可以參考下
    2014-08-08
  • C#讀寫xml文件方法總結(超詳細!)

    C#讀寫xml文件方法總結(超詳細!)

    項目中用到關于xml文件讀寫操,所以下面這篇文章主要給大家介紹了關于C#讀寫xml文件方法的相關資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2023-02-02
  • C#中的應用程序接口介紹及實現(xiàn),密封類與密封方法

    C#中的應用程序接口介紹及實現(xiàn),密封類與密封方法

    今天小編就為大家分享一篇關于C#中的應用程序接口介紹及實現(xiàn),密封類與密封方法,小編覺得內容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2018-10-10
  • C#中使用HttpPost調用WebService的方法

    C#中使用HttpPost調用WebService的方法

    這篇文章介紹了C#中使用HttpPost調用WebService的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-03-03
  • C#算法之無重復字符的最長子串

    C#算法之無重復字符的最長子串

    這篇文章介紹了C#算法之無重復字符的最長子串,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-01-01
  • C#導出文本內容到word文檔的方法

    C#導出文本內容到word文檔的方法

    這篇文章主要介紹了C#導出文本內容到word文檔的方法,涉及C#操作word文檔的相關技巧,需要的朋友可以參考下
    2015-04-04
  • C#使用Socket實現(xiàn)通信的方法示例

    C#使用Socket實現(xiàn)通信的方法示例

    這篇文章主要介紹了C#使用Socket實現(xiàn)通信的方法示例,文章按照 Socket 的 創(chuàng)建、連接、傳輸數(shù)據(jù)、釋放資源的過程來寫,給出方法、參數(shù)的詳細信息,文中有詳細的代碼示例供大家參考,需要的朋友可以參考下
    2024-06-06
  • C#中使用?record?的好處和最佳場景

    C#中使用?record?的好處和最佳場景

    這篇文章主要介紹了C#中使用?record?的好處,使用?record?類型的主要好處包括簡潔的語法、自動生成的成員、基于值的相等性、非破壞性復制、解構支持、繼承支持和與模式匹配的良好集成,需要的朋友可以參考下
    2024-07-07
  • C#中如何利用正則表達式判斷字符

    C#中如何利用正則表達式判斷字符

    這篇文章主要介紹了C#中利用正則表達式判斷字符的實例代碼,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-12-12

最新評論