主窗体:

 String title = LogoConfig.GetLogoConfig("Title");
if(title.Length>0)
{
this.Text = title;
panelCaption.Text = title;
}

String logoImage = LogoConfig.GetLogoConfig("Logo");
if (logoImage.Length > 0)
{
logoImage = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "image\\" + logoImage);
Image logo = Image.FromFile(logoImage);
pictureLogo.Image = logo;
}

logoImage = LogoConfig.GetLogoConfig("Image");
if (logoImage.Length > 0)
{
logoImage = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "image\\" + logoImage);
Image brand = Image.FromFile(logoImage);
pictureBrand.Image = brand;
}

类文件:


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EvenTHZSystem
{
class LogoConfig
{
static Dictionary<string, string> logoconfigmap = new Dictionary<string, string>();
static bool bInitialized = false;
public static string GetLogoConfig(string key)
{

if (!bInitialized)
{
try
{
String logoConfig = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "image\\logo.config");

using (StreamReader reader = new StreamReader(logoConfig))
{
while (!reader.EndOfStream)
{
String line = reader.ReadLine();
string[] kv = line.Split('=');
if (kv != null)
{
logoconfigmap.Add(kv[0], kv[1]);
}
}
}

}
catch { }
bInitialized = true;
}

string value = "";
try
{
value = logoconfigmap[key];
}
catch { }
return value;
}
}
}

配置文件:

C# 修改配置文件进行窗体logo切换_技术交流