Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

save / restore button background color to/from a temporary variable 1

Status
Not open for further replies.

AustinOne

Programmer
Mar 22, 2002
59
US
Hi,

I have searched for this, but couldn't find a specific answer to this:

(Upon some event), I want to temporarily save the background color of a button (whatever that color may be) to a variable, and then, (based on some other event) I want to restore the button's color to the previously saved color stored in that variable. I guess my question has to do with what kind of variable can be used to temporarily save a control's color to and then later restore it from. I don't need to permanently store or persist the value.

Thanks
 
This is what I did for coloring a specific cell in a DataGridView in a nutshell.

Code:
Dim BgColor As Color = Nothing
'assign variable the color.
BgColor = Color.Maroon
'assign the cell the color via the variable.
dgCtl.Item("JobNum", j).Style.BackColor = BgColor

--------------------------------------------------
“Crash programs fail because they are based on the theory that, with nine women pregnant, you can get a baby a month.” --Wernher von Braun
--------------------------------------------------
 
Thanks!

I guess I was trying to make it more complicated than it is.

I also had to experiment with Thread.Sleep and Application.DoEvents in order to get the screen to update/refresh with the changed color on the button.

Thanks again
 
You shouldn't need Sleep, but I had to use DoEvents when in tight loops, etc.

On a good note, if you need to save the color value to a table and then retrieve it later:
Code:
BgColor = Color.FromArgb(intColorValue)
intColorValue = BgColor.ToArgb

The function converts the color to an Integer that can be stored as an INT in the database and then converted back to for display.

--------------------------------------------------
“Crash programs fail because they are based on the theory that, with nine women pregnant, you can get a baby a month.” --Wernher von Braun
--------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top