最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

源文件地址: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ū)不能為空!", "錯(cuò)誤", 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 = "";
    }

  }

} 

 運(yùn)行結(jié)果:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C#中this的用法集錦

    C#中this的用法集錦

    本文給大家匯總介紹了C#中的幾種this用法,相信大家應(yīng)該有用過,但你用過幾種?以下是個(gè)人總結(jié)的this幾種用法,歡迎大家拍磚,廢話少說,直接列出用法及相關(guān)代碼。
    2015-06-06
  • 淺析C# 委托(Delegate)

    淺析C# 委托(Delegate)

    這篇文章主要介紹了C# 委托(Delegate)的相關(guān)資料,文中講解非常詳細(xì),代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-07-07
  • 深入淺析C#中單點(diǎn)登錄的原理和使用

    深入淺析C#中單點(diǎn)登錄的原理和使用

    這篇文章主要介紹了C#中單點(diǎn)登錄的原理和使用,需要的朋友可以參考下
    2017-10-10
  • C#很簡(jiǎn)單而又很經(jīng)典的一句代碼實(shí)例

    C#很簡(jiǎn)單而又很經(jīng)典的一句代碼實(shí)例

    這篇文章主要給大家分享介紹了關(guān)于C#很簡(jiǎn)單而又很經(jīng)典的一句代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用C#具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • 最新評(píng)論

    康马县| 天门市| 调兵山市| 巍山| 兴文县| 湖南省| 广水市| 星子县| 城口县| 桐庐县| 化州市| 綦江县| 邵东县| 阜宁县| 黔西| 惠来县| 长海县| 惠安县| 枣强县| 哈密市| 米易县| 大英县| 镇赉县| 桃江县| 河东区| 京山县| 临泽县| 同江市| 仁怀市| 吕梁市| 衡阳市| 旺苍县| 布尔津县| 安乡县| 凭祥市| 阿坝| 浦江县| 高州市| 凭祥市| 利津县| 蕲春县|