private Color currentColor;
private Color[] skinColors;
private int currentSkinIndex;
public Form1()
{
InitializeComponent();
// 初始化当前颜色为默认颜色
currentColor = Color.LightBlue;
ApplySkin(currentColor);
// 初始化皮肤颜色数组222
skinColors = new Color[] {
Color.Red,
Color.Blue,
Color.Green,
Color.Yellow,
Color.Orange,
Color.Purple,
Color.Pink,
Color.Brown,
Color.Gray,
Color.Black,
Color.White,
Color.Magenta,
Color.Cyan,
Color.Lime,
Color.Teal,
Color.Silver,
Color.Gold,
Color.Navy,
Color.Olive,
Color.Maroon
};
// 初始化当前皮肤索引
currentSkinIndex = 0;
// 应用初始皮肤
ApplySkin(skinColors[currentSkinIndex]);
}
private void button1_Click(object sender, EventArgs e)
{
// 打开颜色选择对话框,让用户选择新的颜色
ColorDialog colorDialog = new ColorDialog();
if (colorDialog.ShowDialog() == DialogResult.OK)
{
// 获取用户选择的颜色
Color selectedColor = colorDialog.Color;
// 应用新的皮肤颜色
ApplySkin(selectedColor);
}
}
private void button2_Click(object sender, EventArgs e)
{
// 切换到下一个皮肤
currentSkinIndex = (currentSkinIndex 1) % skinColors.Length;
// 应用新的皮肤
ApplySkin(skinColors[currentSkinIndex]);
}
设置窗体的背景色
private void ApplySkin(Color color)
{
// 设置窗体的背景色和按钮的背景色
this.BackColor = color;
this.button1.BackColor = color;
// 更新当前颜色
currentColor = color;
}