Load changes only if the button was clicked

0

Windows form I would like to see that if a button was clicked, it will change color, and when the program closes, it will be shown again but with the color changed. Only if you clicked on it.

private bool Clicked;
private void btnA100_Click(object sender, EventArgs e)
    {
        Clicked = true;
        this.btnA100.BackColor = Color.LightSlateGray;
        txtNHabit.Text = "A100";

    }
   private void frmRegistrar_Load(object sender, EventArgs e)
    {

        if (Clicked==true)
        {
            this.btnA100.BackColor = Color.LightSlateGray;
        }

        //this.btnA101.BackColor = Color.LightSlateGray;

    }
    
asked by Darian Ganz 24.11.2018 в 20:23
source

1 answer

0

You could persist the color in the configuration of the application

Using Settings in C #

Then when you press the button you assign to the configuration which color is assigned

private void btnA100_Click(object sender, EventArgs e)
{
   //resto codigo
   Properties.Settings.Default.myColor = Color.LightSlateGray;
   Properties.Settings.Default.Save();
}

private void frmRegistrar_Load(object sender, EventArgs e)
{
   btnA100.BackColor = Properties.Settings.Default.myColor;
}

you only recover the one you have in the configuration

It is clear that by default in the configuration you must assign the color you want to see when the button is not pressed, you can always edit with the notepad the .config to change without recompiling

    
answered by 25.11.2018 в 00:46