|
-
Mar 6th, 2006, 06:21 PM
#1
Thread Starter
New Member
[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
-
Mar 6th, 2006, 06:46 PM
#2
Re: Changing the Background Colour
Put a Microsoft CommonDialog control on a form. Add a command button and do this
VB Code:
Private Sub Command1_Click()
Dim frm As Form
CommonDialog1.ShowColor
For Each frm In Forms
frm.BackColor = CommonDialog1.Color
Next
End Sub
-
Mar 6th, 2006, 06:47 PM
#3
Frenzied Member
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 :\
-
Mar 6th, 2006, 06:58 PM
#4
Frenzied Member
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:
Private Sub Command1_Click()
SetColor
End Sub
Private Sub Form_Load()
Dim color As Variant
color = GetSetting(App.EXEName, "Colors", "Form_Color")
If color = "" Then
If MsgBox("It appears that this is the first time you are using this software" & _
vbNewLine & "Do you want to change the app's color?" & _
"", vbYesNo + vbQuestion, "First time?") = vbNo Then
Else
SetColor
End If
Else
Me.BackColor = color
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
SaveSetting App.EXEName, "Colors", "Form_Color", Me.BackColor
End Sub
Public Sub SetColor()
Dim frm As Form
CommonDialog1.ShowColor
For Each frm In Forms
frm.BackColor = CommonDialog1.color
Next
End Sub
-
Mar 6th, 2006, 06:58 PM
#5
Thread Starter
New Member
Re: Changing the Background Colour
Thank you very much works perfectly
-
Mar 6th, 2006, 07:00 PM
#6
Frenzied Member
Re: Changing the Background Colour
Was your problem resolved?
-
Mar 7th, 2006, 07:54 AM
#7
Thread Starter
New Member
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
-
Mar 7th, 2006, 08:58 AM
#8
Re: [RESOLVED] Changing the Background Colour
 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:
Option Explicit
Private Sub ChangeLabelBkClr(plngColor As Long)
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is Label Then
ctrl.BackColor = plngColor
End If
Next
End Sub
Private Sub Command1_Click()
ChangeLabelBkClr vbRed
End Sub
-
Mar 7th, 2006, 03:04 PM
#9
Re: Changing the Background Colour
 Originally Posted by Argh two glass eyes
Thank you very much works perfectly 
Just in case someone presses Cancel.
VB Code:
Private Sub Command1_Click()
Dim frm As Form
On Error GoTo ErrorRoutine
CommonDialog1.CancelError = True
CommonDialog1.ShowColor
For Each frm In Forms
frm.BackColor = CommonDialog1.Color
Next
Exit Sub
ErrorRoutine:
If Err.Number = 32755 Then
MsgBox "You pressed Cancel rather than selecting a color"
End If
End Sub
-
Mar 7th, 2006, 03:07 PM
#10
Thread Starter
New Member
Re: Changing the Background Colour
 Originally Posted by MartinLiss
Just in case someone presses Cancel.
VB Code:
Private Sub Command1_Click()
Dim frm As Form
CommonDialog1.ShowColor
For Each frm In Forms
frm.BackColor = CommonDialog1.Color
Next
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
-
Mar 7th, 2006, 03:14 PM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|