4 Replies - 2499 Views - Last Post: 21 March 2011 - 04:49 PM Rate Topic: -----

#1 NightmareX91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 13-March 11

How to make button colors changeable

Posted 21 March 2011 - 02:02 PM

I'm working on a game in VB.NET and I had an idea that lets you change button colors before launching the game (made a game launcher) but I can't figure out how to do it.


The original code I set:
buttons(i, column).ForeColor = Color.Blue
buttons(i, column).BackColor = Color.Blue



I want Color.Blue to be changeable in a ComboBox I put in the gamelauncher form. I've tried it like:
buttons(i, column).ForeColor = Gamelauncher.ComboBox2.Text
buttons(i, column).BackColor = Gamelauncher.ComboBox2.Text


But it wouldn't work! :stupid:

If you can, please help me out.

Is This A Good Question/Topic? 0
  • +

Replies To: How to make button colors changeable

#2 ???  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 48
  • Joined: 25-November 10

Re: How to make button colors changeable

Posted 21 March 2011 - 02:33 PM

It's actually quite simple.

buttons(i, column).ForeColor = Color.FromName(Gamelauncher.ComboBox2.Text)
buttons(i, column).BackColor = Color.FromName(Gamelauncher.ComboBox2.Text)


Was This Post Helpful? 2
  • +
  • -

#3 NightmareX91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 13-March 11

Re: How to make button colors changeable

Posted 21 March 2011 - 02:34 PM

View Post???, on 21 March 2011 - 02:33 PM, said:

It's actually quite simple.

buttons(i, column).ForeColor = Color.FromName(Gamelauncher.ComboBox2.Text)
buttons(i, column).BackColor = Color.FromName(Gamelauncher.ComboBox2.Text)


Thanks :D! Now I can continue with the game!
Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1623
  • View blog
  • Posts: 5,199
  • Joined: 25-September 09

Re: How to make button colors changeable

Posted 21 March 2011 - 02:37 PM

That's cool, I never knew it existed.
Was This Post Helpful? 0
  • +
  • -

#5 Shadar  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 157
  • Joined: 26-May 09

Re: How to make button colors changeable

Posted 21 March 2011 - 04:49 PM

Here....you might be interested in this also.
Bear in mind the me.setstyle statment must be used when you are going to change the backcolor of the form like this because of the transparency property. If you don't use it, it won't work.

 Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim clr As Color
        clr = Color.FromName(ComboBox1.Text)
        Button1.BackColor = clr
    End Sub

    Private Sub LoadColors()
        Dim colorsArray As System.Array = [Enum].GetValues(GetType(KnownColor))
        For x As Integer = 0 To colorsArray.Length - 1
            ComboBox1.Items.Add(colorsArray(x).ToString)
        Next
    End Sub

    Private Sub frmGraphics_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
        LoadColors()
    End Sub



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1