winform客户端程序实时读写app.config文件
新接到需求,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文件的更多相关文章
- c#Winform程序调用app.config文件配置数据库连接字符串 SQL Server文章目录 浅谈SQL Server中统计对于查询的影响 有关索引的DMV SQL Server中的执行引擎入门 【译】表变量和临时表的比较 对于表列数据类型选择的一点思考 SQL Server复制入门(一)----复制简介 操作系统中的进程与线程
c#Winform程序调用app.config文件配置数据库连接字符串 你新建winform项目的时候,会有一个app.config的配置文件,写在里面的<connectionStrings n ...
- WPF程序中App.Config文件的读与写
WPF程序中的App.Config文件是我们应用程序中经常使用的一种配置文件,System.Configuration.dll文件中提供了大量的读写的配置,所以它是一种高效的程序配置方式,那么今天我就 ...
- [C#.Net]对WinForm应用程序的App.config的使用及加密
我们在写C#应用程序时,在工程文件中放置一个app.config,程序打包时,系统会将该配置文件自动编译为与程序集同名的.exe.config 文件.作用就是应用程序安装后,只需在安装目录中找到该文件 ...
- C# 对WinForm应用程序的App.config的使用及加密
原文地址:http://blog.163.com/zhou_zzq/blog/static/1019622120137621739874/ 我们在写C#应用程序时,在工程文件中放置一个app.co ...
- C# 对WinForm应用程序的App.config的加密
默认情况下,我们需要对App.config文件里的connectionStrings片断进行加密处理,ASP.NET IIS 注册工具 (Aspnet_regiis.exe)可以胜任这个工作,但这个工 ...
- c#Winform程序调用app.config文件配置数据库连接字符串
你新建winform项目的时候,会有一个app.config的配置文件,写在里面的<connectionStrings name=" " connectionString= ...
- C#/ASP.NET应用程序配置文件app.config/web.config的增、删、改操作
原文 http://www.cnblogs.com/codealone/archive/2013/09/22/3332607.html 应用程序配置文件,对于asp.net是 web.config,对 ...
- C#/ASP.NET应用程序配置文件app.config/web.config的增、删、改操作,无法为请求的 Configuration 对象创建配置文件。
应用程序配置文件,对于asp.net是 web.config,对于WINFORM程序是 App.Config(ExeName.exe.config). 配置文件,对于程序本身来说,就是基础和依据,其本 ...
- C# 应用程序配置文件App.Config和web.config
应用程序配置文件,对于asp.net是 web.config,对于WINFORM程序是 App.Config(ExeName.exe.config). 配置文件,对于程序本身来说,就是基础和依据,其本 ...
随机推荐
- 五:SQL语句中的数据类型
一:MySQL数据类型 MySQL中定义数据字段的类型对你数据库的优化是非常重要的 MySQL支持多种数据类型,大致可以分为三类:数值 日期/时间和字符串 二.数值类型(12) 2.1.整数类型(6) ...
- webpack hmr
参考: https://webpack.js.org/concepts/hot-module-replacement/ https://webpack.js.org/guides/hot-module ...
- Luogu 2627 修建草坪 (动态规划Dp + 单调队列优化)
题意: 已知一个序列 { a [ i ] } ,求取出从中若干不大于 KK 的区间,求这些区间和的最大值. 细节: 没有细节???感觉没有??? 分析: 听说有两种方法!!! 好吧实际上是等价的只是看 ...
- PYDay7&8-递归、冒泡算法、装饰器
1.登录验证代码 1.1纯登录验证-函数实现 def login(username,password): ''' 用于用户名密码的验证 :param username: 用户名 :param pass ...
- luogu3761 [TJOI2017]城市
重点是求树的直径.半径. 参考这里 #include <iostream> #include <cstring> #include <cstdio> using n ...
- Linux基础命令详解-2
本篇详解的命令有以下30个 1.rmdir 功能:删除一个空目录 2.telnet 功能:使用telnet协议连接到主机的指定端口 3.vim 功能:编辑器之神 vim三种模式的功能及其转换 ...
- 读CSS DIV网页样式与布局心得体会
一.首先根据网页设计图拆分网页的整体结构 二.在html页面用DIV划分出结构块 三.再根据设计图在各个大<DIV>块中加入对应的小<DIV>块或者段落<P>,表单 ...
- VOC Segmentation GT图像颜色表生成分析
本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/52185581 PASCAL VOC图像 ...
- 使用python实现简单的爬虫
python爬虫的简单实现 开发环境的配置 python环境的安装 编辑器的安装 爬虫的实现 包的安装 简单爬虫的初步实现 将数据写入到数据库-简单的数据清洗-数据库的连接-数据写入到数据库 开发环境 ...
- EasyUI 动态生成列加分页
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=&qu ...