Reset background color of textbox

14,121

Solution 1

Simply:

TextBox1.BackColor = SystemColors.Window

Solution 2

You reset the color by re-assigning the original value of BackColor. Or by assigning the default value, it isn't white:

 textBox1.BackColor = Color.FromKnownColor(KnownColor.Window);
Share:
14,121

Related videos on Youtube

jamesdlivesinatree
Author by

jamesdlivesinatree

Rails. JS. I make music too.

Updated on July 23, 2022

Comments

  • jamesdlivesinatree
    jamesdlivesinatree over 1 year

    I'm using VS2012 with VB.NET on a winforms application. I set the BackColor property of some textboxes programmatically during my code depending on form validation. This works fine, the problem is that I'd like to "reset" the BackColor property of the textbox, so that the textbox performs as if it were in the same state before I set the BackColor. So it would do the following:

    Return to the default color of white immediately after "reset"

    Change to that "light gray" color when the textbox.enabled = false

    The reason why I cannot simply set the BackColor to Color.White, is that this affects the textbox when textbox.enabled = false. The textbox does not return that "light gray" color after setting the backcolor and disabling the textbox. I need it to return to that color, and I'd rather not have to set the textbox's color everytime I enable or disable the textbox. Thanks!