//您好, 我想写一个软件,并且对于“单击按钮时保持按钮选择(我的意思是背景颜色)感到困惑,直到我点击另一个”
如果有人可以帮助我,我会非常感激。 在此先感谢//
namespace SoftwareUI
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
button1.ForeColor = Color.LightGray;
}
private void button1_Leave(object sender, EventArgs e)
{
button1.ForeColor = Color.GhostWhite;
}
private void button1_MouseEnter(object sender, EventArgs e)
{
button1.ForeColor = Color.LightSlateGray;
}
}
}
答案 0 :(得分:1)
为所有按钮的点击事件添加此代码:
Button b = (Button)sender;
b.BackColor = Color.LightGray;
foreach (Button bt in b.Parent.Controls.OfType<Button>())
{
if (bt != b)
bt.BackColor = Color.White;
}