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
Printable View
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
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
The best way to do it is to use the "Microsoft Common Dialog Control"
Edit: I see MartinLiss Beat ME :\
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
Thank you very much works perfectly :)
Was your problem resolved?
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.Quote:
Originally Posted by Argh two glass eyes
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
Just in case someone presses Cancel.Quote:
Originally Posted by Argh two glass eyes
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
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 :(Quote:
Originally Posted by MartinLiss
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