您的位置:首页 > Web前端 > CSS

C# WinForm (笨方法)根据不同的样式配置 设置窗体相关控件的背景 以改变窗体风格

2008-11-24 11:07 1051 查看
//1. 项目下增加相关图片文件夹

------------------------------

--项目WinFormStudy

--窗体LoginForm.cs

--窗体MainForm.cs

--文件夹StyleImage

--子文件夹StyleA

--相关图片btnAddUser.JPG及其他

(将图片做为 嵌入的资源 进行生成)

--子文件夹StyleB

--相关图片btnAddUser.JPG及其他

//2. App.config中保存当前窗体的风格

------------------------------------

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<appSettings>

<add key="CurrentStyle" value="StyleB"/>

</appSettings>

...

</configuration>

//3. 窗体调用

----------------

DrawStylePicture.DrawButtonBackgroundImage(this.btnAddUser, "btnAddUser.JPG");

//4. DrawStylePicture

-----------------------

Code

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using System.Windows.Forms;

namespace WinFormStudy

{

class AppConfigXMLManage

{

public static string GetAppConfig(string strKey)

{

//return System.Configuration.ConfigurationManager.AppSettings[strKey];

XmlDocument doc = new XmlDocument();

try

{

doc.Load(Application.ExecutablePath + ".config");

XmlNode node = doc.SelectSingleNode(@"//add[@key='" + strKey + "']");

XmlElement ele = (XmlElement)node;

return ele.GetAttribute("value");

}

catch

{

return string.Empty;

}

}

public static bool UpdateAppConfig(string strKey, string strValue)

{

XmlDocument doc = new XmlDocument();

try

{

doc.Load(Application.ExecutablePath + ".config");

XmlNode node = doc.SelectSingleNode(@"//add[@key='" + strKey + "']");

XmlElement ele = (XmlElement)node;

ele.SetAttribute("value", strValue);

doc.Save(Application.ExecutablePath + ".config");

}

catch

{

return false;

}

return true;

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: