Results 1 to 11 of 11

Thread: [RESOLVED] Changing the Background Colour

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2005
    Location
    Glastonbruy
    Posts
    14

    Resolved [RESOLVED] Changing the Background Colour

    Hi

    I want to make it so the suer can change the background colour of all forms with in my program. i want them to be able to have a variety of colours to choose from. what is the best way if any of doing this.

    Thanks in advance
    Last edited by Hack; Mar 7th, 2006 at 06:55 AM. Reason: Added [RESOLVED] to thread title and green "resolved" checkmark

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Changing the Background Colour

    Put a Microsoft CommonDialog control on a form. Add a command button and do this

    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3. Dim frm As Form
    4.  
    5. CommonDialog1.ShowColor
    6. For Each frm In Forms
    7.     frm.BackColor = CommonDialog1.Color
    8. Next
    9.  
    10. End Sub

  3. #3
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: Changing the Background Colour

    The best way to do it is to use the "Microsoft Common Dialog Control"

    Edit: I see MartinLiss Beat ME :\
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  4. #4
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: Changing the Background Colour

    You can save the color info so the user won't need to choose a it allover again every time:

    VB Code:
    1. Private Sub Command1_Click()
    2.     SetColor
    3. End Sub
    4.  
    5. Private Sub Form_Load()
    6. Dim color As Variant
    7.     color = GetSetting(App.EXEName, "Colors", "Form_Color")
    8. If color = "" Then
    9.     If MsgBox("It appears that this is the first time you are using this software" & _
    10.                  vbNewLine & "Do you want to change the app's color?" & _
    11.                  "", vbYesNo + vbQuestion, "First time?") = vbNo Then
    12.         Else
    13.             SetColor
    14.     End If
    15. Else
    16.     Me.BackColor = color
    17. End If
    18. End Sub
    19.  
    20. Private Sub Form_Unload(Cancel As Integer)
    21.     SaveSetting App.EXEName, "Colors", "Form_Color", Me.BackColor
    22. End Sub
    23.  
    24. Public Sub SetColor()
    25. Dim frm As Form
    26.     CommonDialog1.ShowColor
    27. For Each frm In Forms
    28.     frm.BackColor = CommonDialog1.color
    29. Next
    30. End Sub
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2005
    Location
    Glastonbruy
    Posts
    14

    Re: Changing the Background Colour

    Thank you very much works perfectly

  6. #6
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: Changing the Background Colour

    Was your problem resolved?
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2005
    Location
    Glastonbruy
    Posts
    14

    Re: [RESOLVED] Changing the Background Colour

    Similar Problem if a dark colour is selcted the text i use on the forums cant be seen. can i do a similar thing to change all the text of the labels.

    thanks

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] Changing the Background Colour

    Quote Originally Posted by Argh two glass eyes
    Similar Problem if a dark colour is selcted the text i use on the forums cant be seen. can i do a similar thing to change all the text of the labels.

    thanks
    Sure. Instead of passing a hardcoded color as I do in my example, pass the results of the color dialog selection.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub ChangeLabelBkClr(plngColor As Long)
    4. Dim ctrl As Control
    5. For Each ctrl In Me.Controls
    6.     If TypeOf ctrl Is Label Then
    7.        ctrl.BackColor = plngColor
    8.     End If
    9. Next
    10. End Sub
    11.  
    12. Private Sub Command1_Click()
    13. ChangeLabelBkClr vbRed
    14. End Sub

  9. #9
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Changing the Background Colour

    Quote Originally Posted by Argh two glass eyes
    Thank you very much works perfectly
    Just in case someone presses Cancel.

    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3. Dim frm As Form
    4.  
    5. On Error GoTo ErrorRoutine
    6.  
    7. CommonDialog1.CancelError = True
    8. CommonDialog1.ShowColor
    9. For Each frm In Forms
    10.     frm.BackColor = CommonDialog1.Color
    11. Next
    12.  
    13. Exit Sub
    14.  
    15. ErrorRoutine:
    16.  
    17.     If Err.Number = 32755 Then
    18.         MsgBox "You pressed Cancel rather than selecting a color"
    19.     End If
    20.  
    21. End Sub

  10. #10

    Thread Starter
    New Member
    Join Date
    Jan 2005
    Location
    Glastonbruy
    Posts
    14

    Re: Changing the Background Colour

    Quote Originally Posted by MartinLiss
    Just in case someone presses Cancel.

    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3. Dim frm As Form
    4.  
    5. CommonDialog1.ShowColor
    6. For Each frm In Forms
    7.     frm.BackColor = CommonDialog1.Color
    8. Next
    9.  
    10.  
    11. End Sub
    Thanks but i'm now having the problem of it only changing the background colour of two forms. the one that i select the colour in and a main menu form

  11. #11
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: [RESOLVED] Changing the Background Colour

    It will only change the color of the currently loaded forms. If you want to change the color of forms loaded later, put the following in their Load subs.

    Me.BackColor = Form1.CommonDialog1.Color

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width