coloring buttons by code

Hello,
I have these two buttons named:
------------------
button1
button2
----------------
and there is:
--------------
label1
--------------


and when button1 is pressed it will excute this code:

label1.Text = "button1"

and when button2 is pressed, it will excute this code:

label1.Text = "button2"

and I also have this code (gets excuted when my imagebox's image location changes):
--------------------------------------------------------
Private Sub mapBox_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles mapBox.LocationChanged

If label1.Text = "button1" Then
button1.BackColor = System.Drawing.SystemColors.MenuHighlight
button1.ForeColor = System.Drawing.SystemColors.Window

button2.BackColor = System.Drawing.SystemColors.Window
button2.ForeColor = System.Drawing.SystemColors.ControlText

End If

If label1.Text = "button2" Then
button2.BackColor = System.Drawing.SystemColors.Menuhighlight
button2.ForeColor = System.Drawing.SystemColors.Window

button1.BackColor = System.Drawing.SystemColors.Window
button1.ForeColor = System.Drawing.SystemColors.ControlText
End If

End Sub
-----------------------------------------------------

but the problem is that when the I click the button and label's text changes to respective text,
neither button's backcolor OR forecolor change

what's up with the deal

I also have tried
---------------------------------------------
Imports.System.Drawing.SystemColors
--------------------------------------------
at the way top...
but does not help...

ANY form of help would be appriciated!

Thank You!
Keehun Nam





Answer this question

coloring buttons by code

  • Amit Pandya

    oh, so when it says,

    LocationChanged

    then does it mean the literal location (x,y) of the picturebox itself
    If so, Thank you! for letting me know! I learned something!


  • Clement Pang

    It's where you have the code located.

    It doesn't execute when the buttons are clicked instead it executes when some control is moved.



  • raider123

    G'day Keehun Nam.

    If I understand your question right, then try this. I think that it does what you were asking for.

    Just call it from either of your button_click events.

  • coloring buttons by code