Change the color of a button permanently when clicking

0

I know how to change the color, but when I close the program the change is not saved. I would like the change to be seen when the program opens again. The code he used was this:

private void btnA100_Click(object sender, EventArgs e)
        {
            this.Controls.OfType<Button>().ToList().ForEach(x => x.BackColor = Color.DodgerBlue);

        ((Button)sender).BackColor = Color.LightSlateGray;
        txtNHabit.Text = "A100";
    }
    
asked by Darian Ganz 24.11.2018 в 02:43
source

1 answer

0

Your problem is occurring because you are modifying the aesthetics of your buttons in the wrong place.

The btnA100_Click method is executed only when clicking on a button (I assume btnA100 ).

If what you are looking for is to paint at startup, you can do it using either the constructor of your form, or the event Load of it.

public partial class Form1 : Form
{              
        public Form1()
        {
            InitializeComponent();
            //Acá podes pintarlo de la manera que lo haces.
        }
}

Or also, as I mentioned above, you can subscribe the form to the event Load , for example

this.Load += Form1_Load1; //Asumiendo que this referencia a tu Form

and then in what you paint in the method associated with the event

private void Form1_Load1(object sender, EventArgs e)
      {
          //Aca podes pintarlo de la manera que lo haces.
      }

I hope I have clarified your doubts.

    
answered by 24.11.2018 / 04:40
source