對於同一個窗體來說,點擊窗體就改變背景顏色,怎麼做的呢,其實很簡單的啦,就是在單擊事件裡進行判斷,代碼如下:
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 ChangeColor
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.BackColor = Color.Blue;
}
private void Form1_Click(object sender, EventArgs e)
{
if (this.BackColor == Color.Blue)
{
this.BackColor = Color.Green;
}
else if (this.BackColor == Color.Green)
{
this.BackColor = Color.LightPink;
}
else if (this.BackColor == Color.LightPink)
{
this.BackColor = Color.Red;
}
else if (BackColor == Color.Red)
{
this.BackColor = Color.Blue;
}
}
}
}