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;
}
}
}
------------------------------
--项目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;
}
}
}
相关文章推荐
- C# WinForm (笨方法)根据不同的样式配置 设置窗体相关控件的背景 以改变窗体风格
- c#一种简单快速改变窗体风格和肤色的方法源码及其控件
- c# winform 用子窗体刷新父窗体,子窗体改变父窗体控件的值两种方法(2)
- C#实现winform用子窗体刷新父窗体及子窗体改变父窗体控件值的方法
- c#一种简单快速改变窗体风格和肤色的方法源码及其控件001
- 【C#基础】之WinForm窗体常用控件的属性、方法及事件简介
- Flex中通过设置fillColors样式改变ComboBox控件的填充背景颜色的例子
- c# 改变Mdi窗体区背景样式
- c# winform 用子窗体刷新父窗体,子窗体改变父窗体控件的值
- 【C#基础】之WinForm窗体常用控件的属性、方法及事件简介 .
- C#里WinForm开发中如何实现控件随窗体大小的改变而自动适应其改变
- C#里WinForm开发中如何实现控件随窗体大小的改变而自动适应其改变
- C#中WinForm实现控件随窗体大小自适应改变
- C#中自Photoshop样式的角度和高度选择器控件的创建方法(WinForm)
- C# WinForm控件随窗体大小改变自动适应改变
- C# winform中一个类中如何调用另一个窗体的控件或方法
- C# winform中一个类中如何调用另一个窗体的控件或方法
- winform开发中,不同窗体根据显示需要进行不同设置,Form属性设置介绍如下。
- C# WinForm窗体控件Panel修改边框颜色以及边框宽度方法