久久久久久久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à)值,感興趣的小伙伴們可以參考一下
主站蜘蛛池模板: 国产精品一区二区视频 | 伊人精品国产 | 欧美影院 | 成人久久一区 | 久久国产一区二区三区 | 午夜视频在线免费观看 | 日韩av高清在线 | 亚洲精品二区 | 精品91| 欧美一级电影免费观看 | 精品一区久久 | 久操伊人 | 亚洲视频 欧美视频 | 婷婷桃色网 | 欧美精品一二三区 | 日韩在线免费 | 一级做a| 日日操操 | 欧美成人激情 | 欧美精品在线播放 | 欧美日韩中文国产一区发布 | 欧美在线视频一区 | 精品视频一区二区 | 免费成人在线网站 | 色综合天天天天做夜夜夜夜做 | 极品一区| 久久男女视频 | 免费观看黄色片视频 | 国产精品高潮呻吟久久久久 | 国产精品毛片无码 | av在线免费网站 | 午夜亚洲 | 天天操夜夜拍 | 国产在线精品一区二区三区 | 黄色片免费在线观看 | 久久出精品 | 亚洲欧美一区二区三区在线 | 一本一道久久a久久精品蜜桃 | 黄色一级毛片免费看 | 精品久久久久国产 | 国产精品久久久久久久久久久免费看 |