Home > Back-end >  When changing form background color I'm getting the indexer is read only error
When changing form background color I'm getting the indexer is read only error

Time:12-11

I am trying to make a dark mode for my Windows forms app but am getting and error. Never set any property of my form to read only neither can I find and option to set it to read only

public void TemniNacin()
        {
            LetalskaDruzba.DefaultBackColor = Color.Black;
            foreach (var textboxi in Controls.OfType<TextBox>())
            {
                textboxi.BackColor= Color.Black;
                textboxi.ForeColor = Color.White;
            }
        }

error is happening in the 3rd line

CodePudding user response:

The enter image description here

You can assign this color to the form instance instead:

BackColor = Color.Black;

I assume that this code is inside a Form and that LetalskaDruzba is the form name. Then you can access the properties, fields and methods of this form directly. No need to prepend it a this. as in this.BackColor = Color.Black;.

  • Related