这就是我正在做的事情。
我有三个属性:MomsBackground、DadsBackground 和 ChosenBackground。
当在程序中选择了 Momsbackground 时,我根据用户单击的项目(“妈妈”或“爸爸”)设置了 ChosenBackground 字符串。
然后在 Form_Load() 上,我为 ChosenBackground 字符串使用一个 switch case,并根据它选择 This.BackgroundColor 到 MomsBackground 或 DadsBackground。
下面的代码:我是否按预期使用它?对不起,现在有代码。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void momToolStripMenuItem_Click(object sender, EventArgs e)
{
this.BackColor = Properties.Settings.Default.MomFormColor;
Properties.Settings.Default.SelectedTheme = "Mom";
Properties.Settings.Default.Save();
}
private void dadToolStripMenuItem_Click(object sender, EventArgs e)
{
this.BackColor = Properties.Settings.Default.DadFormColor;
Properties.Settings.Default.SelectedTheme = "Dad";
Properties.Settings.Default.Save();
}
private void Form1_Load(object sender, EventArgs e)
{
switch (Properties.Settings.Default.SelectedTheme)
{
case "Mom":
this.BackColor = Properties.Settings.Default.MomFormColor;
break;
case "Dad":
this.BackColor = Properties.Settings.Default.DadFormColor;
break;
default:
break;
}
}
}
}