【问题标题】:Visual Studio Windows.Forms Button Background Color selected when Click单击时选择的 Visual Studio Windows.Forms 按钮背景颜色
【发布时间】:2018-07-07 11:52:26
【问题描述】:

//嗨, 我想编写一个软件并且对“单击按钮时保持选中按钮(我的意思是背景颜色),直到我单击另一个按钮”感到困惑

如果有人可以帮助我,我将不胜感激。 提前致谢//

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;
        }    
    }
}

【问题讨论】:

标签: c# winforms visual-studio button


【解决方案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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-09
    • 2021-03-28
    • 2017-08-02
    • 2014-10-10
    • 2017-01-26
    相关资源
    最近更新 更多