新接到需求,wcf客户端程序运行时,能实时修改程序的打印机名称;

使用XmlHelper读写 winform.exe.config文件修改后始终,不能实时读取出来,查询博客园,原来已有大神解释了;

获取电脑连接的打印机列表需要引入using System.Drawing.Printing;

       #region GetPrinters
private List<string> GetPrinters()
{
var printerNames = new List<string>();
foreach (var printer in PrinterSettings.InstalledPrinters)
{
printerNames.Add(printer.ToString());
}
return printerNames;
}
#endregion

指定打印机列表默认显示打印机为配置文件中的打印机:

     printerNames.ForEach(o =>
{
if (defaultPrinter == o)
cbxPrinterList.SelectedIndex = printerNames.IndexOf(o);
});

确定按钮修改默认打印机名称

          #region 判断是否有key
if (ConfigurationManager.AppSettings["DefaultPrinterName"] == null)
{
XmlHelper.UpdateKey("DefaultPrinterName", "ZDesigner GT800-300dpi EPL", WMSWinConstant.ApplicatonName + ".exe");
}
else
{
var printerName = cbxPrinterList.Text; //string appDomainConfigFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
AppSettingsSection appSettings = (AppSettingsSection)config.GetSection("appSettings");
appSettings.Settings["DefaultPrinterName"].Value = printerName;
config.Save();
//重点这句
ConfigurationManager.RefreshSection("appSettings");
}
#endregion
 获取默认打印机

public  static PrintDocument fPrintDocument = new PrintDocument();

//获取本机默认打印机名称
public static String DefaultPrinter()
{
return fPrintDocument.PrinterSettings.PrinterName;
}

 

winform客户端程序实时读写app.config文件的更多相关文章

  1. c#Winform程序调用app.config文件配置数据库连接字符串 SQL Server文章目录 浅谈SQL Server中统计对于查询的影响 有关索引的DMV SQL Server中的执行引擎入门 【译】表变量和临时表的比较 对于表列数据类型选择的一点思考 SQL Server复制入门(一)----复制简介 操作系统中的进程与线程

    c#Winform程序调用app.config文件配置数据库连接字符串 你新建winform项目的时候,会有一个app.config的配置文件,写在里面的<connectionStrings n ...

  2. WPF程序中App.Config文件的读与写

    WPF程序中的App.Config文件是我们应用程序中经常使用的一种配置文件,System.Configuration.dll文件中提供了大量的读写的配置,所以它是一种高效的程序配置方式,那么今天我就 ...

  3. [C#.Net]对WinForm应用程序的App.config的使用及加密

    我们在写C#应用程序时,在工程文件中放置一个app.config,程序打包时,系统会将该配置文件自动编译为与程序集同名的.exe.config 文件.作用就是应用程序安装后,只需在安装目录中找到该文件 ...

  4. C# 对WinForm应用程序的App.config的使用及加密

    原文地址:http://blog.163.com/zhou_zzq/blog/static/1019622120137621739874/   我们在写C#应用程序时,在工程文件中放置一个app.co ...

  5. C# 对WinForm应用程序的App.config的加密

    默认情况下,我们需要对App.config文件里的connectionStrings片断进行加密处理,ASP.NET IIS 注册工具 (Aspnet_regiis.exe)可以胜任这个工作,但这个工 ...

  6. c#Winform程序调用app.config文件配置数据库连接字符串

    你新建winform项目的时候,会有一个app.config的配置文件,写在里面的<connectionStrings name="  " connectionString= ...

  7. C#/ASP.NET应用程序配置文件app.config/web.config的增、删、改操作

    原文 http://www.cnblogs.com/codealone/archive/2013/09/22/3332607.html 应用程序配置文件,对于asp.net是 web.config,对 ...

  8. C#/ASP.NET应用程序配置文件app.config/web.config的增、删、改操作,无法为请求的 Configuration 对象创建配置文件。

    应用程序配置文件,对于asp.net是 web.config,对于WINFORM程序是 App.Config(ExeName.exe.config). 配置文件,对于程序本身来说,就是基础和依据,其本 ...

  9. C# 应用程序配置文件App.Config和web.config

    应用程序配置文件,对于asp.net是 web.config,对于WINFORM程序是 App.Config(ExeName.exe.config). 配置文件,对于程序本身来说,就是基础和依据,其本 ...

随机推荐

  1. service worker 消息推送

    https://developers.google.com/web/fundamentals/codelabs/push-notifications/?hl=en 首先下载源码: git clone ...

  2. clock gate

    clock gate 这个专题,比较复杂设计DC  PT PR.下面仅仅从RTL行为级说明一下.

  3. 模块导入及使用,关键字,模块搜索路径,python文件的两种用途

    06.05自我总结 一.模块导入及使用 1.模块导入的两种方式 我们拿time模块并使用其中的time功能进行举例 a)第一种 import time print(time.time) import首 ...

  4. Python把类当做字典来访问

    定义一个类将它实例化,我们可以通过obj.属性来访问类的属性,如果想获取类的所有实例变量,我们可以使用obj.__dict__来访问,如下: class A: def __init__(self): ...

  5. day21-python模块

    1.时间 import time #时间戳 #计算 # print(time.time()) #1481321748.481654秒 #结构化时间---当地时间 # print(time.localt ...

  6. logistic回归原理和公式

    转自:http://blog.csdn.net/ariessurfer/article/details/41310525 Logistic回归为概率型非线性回归模型,是研究二分类观察结果与一些影响因素 ...

  7. C#学习基础概念二十五问

    C#学习基础概念二十五问 1.静态变量和非静态变量的区别?2.const 和 static readonly 区别?3.extern 是什么意思?4.abstract 是什么意思?5.internal ...

  8. [转]常见linux命令用法介绍

    su switch user 用途:用于用户之间的切换 格式: su - USERNAME切换用户后,同时切换到新用户的工作环境中 su USERNAME切换用户后,不改变原用户的工作目录,及其他环境 ...

  9. iOS学习笔记18-CoreData

    一.CoreData介绍 CoreData是iOS5之后新出来的的一个框架, 是对SQLite进行一层封装升级后的一种数据持久化方式.它提供了对象<-->关系映射的功能,即能够将OC对象转 ...

  10. [BZOJ2118] 墨墨的等式(最短路)

    传送门 好神啊.. 需要用非负数个a1,a2,a3...an来凑出B 可以知道,如果一个数x能被凑出来,那么x+a1,x+a2.......x+an也都能被凑出来 那么我们只需要选择a1~an中任意一 ...