zoukankan      html  css  js  c++  java
  • 通过配置文件判断程序首次启动

    //step 1 .设置配置文件

    App.config:

    <?xml version="1.0"?>
    <configuration>
      <appSettings>
        <add key="IsFirstRun" value="true"></add>
      </appSettings>
    </configuration>

     //step 2.

    注意引用:System.Configuration.dll

    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Linq;
    using System.Text;

    namespace RuiSoft.Common
    {
      public class IsSoftFirstRun
      {

        //返回true为首次启动,返回false为非首次启动
        public static bool IsFirstStart()
        {
          string strIsFirstRun = "false";
          bool isFirstRun = false;
          //strIsFirstRun = ConfigurationManager.AppSettings("IsFirstRun");
          strIsFirstRun = System.Configuration.ConfigurationManager.AppSettings["IsFirstRun"];

          if (string.IsNullOrEmpty(strIsFirstRun) || strIsFirstRun.ToLower() != "true")
          {
            isFirstRun = false;
          }
          else
          {
            isFirstRun = true;
          }
          strIsFirstRun = "false";

          Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
          config.AppSettings.Settings.Remove("IsFirstRun");
          config.AppSettings.Settings.Add("IsFirstRun", strIsFirstRun);
          config.Save();

          return isFirstRun;
        }  
      }
    }

    //step 4. 

    public partial class MainWindow : Window
    {
      public MainWindow()
      {
        InitializeComponent();
        LoadInformation();
      }

      public void LoadInformation()
      {
        if (IsFirstStart())
        {
          txtTest.Text = "首次启动";
        }
        else
        {
          txtTest.Text = "非首次启动";
        }
      }

     }

    //step 4.运行项目下的bin目录下的.exe文件,实现判断首次运行

  • 相关阅读:
    客户端组建调用
    串口开发
    C/C++,系统知识考点
    API进程线程函数
    做WEB2.0网站可以参考的十九条规则
    javascript中动态添加事件!!
    常用正则表达式收集!
    CuteChat for Community Server 2.0 beta 3!
    发现一个下载.Text Skin 的好网站.
    如何控制Linux终端打印字符颜色和位置
  • 原文地址:https://www.cnblogs.com/gnsds/p/3644664.html
Copyright © 2011-2022 走看看