久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

這篇文章主要為大家詳細(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é)果:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持html5模板網(wǎng)。

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

這篇文章主要介紹了C# 將Access中以時(shí)間段條件查詢的數(shù)據(jù)添加到ListView中,需要的朋友可以參考下
這篇文章主要介紹了使用C#創(chuàng)建Windows服務(wù)的實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
這篇文章主要介紹了C#身份證識(shí)別相關(guān)技術(shù)詳解,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
這篇文章主要為大家詳細(xì)介紹了C#中TCP粘包問題的解決方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
這篇文章主要介紹了C#實(shí)現(xiàn)的海盜分金算法,結(jié)合具體實(shí)例形式分析了海盜分金算法的原理與C#相應(yīng)實(shí)現(xiàn)技巧,需要的朋友可以參考下
這篇文章主要為大家詳細(xì)介紹了C#泛型類創(chuàng)建與使用的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
主站蜘蛛池模板: 啪啪综合网 | 国产精品美女久久久久久久久久久 | 99精品视频在线观看免费播放 | 国产精品免费一区二区三区四区 | 日本欧美国产在线 | 免费一级欧美在线观看视频 | 国家aaa的一级看片 h片在线看 | 国产一区二区三区 | 成人二区三区 | 91精品国产91久久久久久吃药 | 成人a在线 | a级在线免费 | 欧洲成人午夜免费大片 | 欧美天堂 | 国产99视频精品免费播放照片 | 亚洲成人一区二区三区 | 久久久精品一区二区三区 | 日韩精品在线观看一区二区 | 国产在线观看一区二区 | 国产一级片一区二区三区 | 国产高清免费 | 丁香婷婷在线视频 | 男人亚洲天堂 | 亚洲精品在线免费看 | 韩日av在线 | 四虎影院免费在线播放 | www.99热.com| 夜夜夜久久久 | 精品九九九 | 99久热| 国产精品自拍视频网站 | 国产欧美一区二区三区在线看蜜臀 | 性一交一乱一透一a级 | 亚洲久草视频 | 求个av网址 | 亚洲日韩中文字幕一区 | av天天爽| 国产精品久久久 | 在线免费观看成人 | 成人久久18免费网站麻豆 | 日韩区|