Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Allowing the user to change the color on forms

Status
Not open for further replies.

LandMonster

Programmer
Feb 4, 2002
11
CA
I'm writing an application and I want to allow the user to be able to change the color of the forms. Obviously I'm not going to allow them to go into design view and change it that way.
I know the backcolor method will allow me to change the color of my forms, but I can't think of a good way to let the user use this method. One solution would be to make them enter the color number and assign it that way. That's not very user friendly though.
What I would like to do is allow the user to choose a color from that little color dialog box (the one that comes up when you are selecting the color). Does anybody know how I can show that to the user? If it's not possible, does anybody have any suggestions for how I could make something similar, or any alternative solutions to this problem? Any help or suggestions are greatly appreciated.
 
Hi there, Just a suggestion....

Why dont you create a small table with a few defined colours?, each colour has a number which will be the [Backcolour], you could create a Combo that gives the user the right to select the required colour. Create a code that changes the backcolour when the user's selection is made.

Have fun...
 
The following code will do it for you. You pass it the "property" that you want to alter.
Example:

Dim lngRet As Boolean
' Pass TextBox ForeColor property to function
lngRet = aDialogColor(Me.textCtl.Properties("ForeColor"))
' If error set ForeColor to Black
If lngRet = False Then
Me.textCtl.Properties("ForeColor") = 0
End If


Paste it into a new module and then test it by calling the function : aDialogColor

' If you want the Function to simply Return
' the Value of the Color the user selected
' from the Dialog just change the Function
' Declaration in modColorPicker to something like:
'Public Function DialogColor(ctl As Control) As Long
' Remember to add the line of code at the
' end of the Function
'DialogColor = CS.rgbResult
' Then call it from your Form with code like:

'***Code Start
'Private Sub CmdChooseBackColor_Click()
' Pass the TextBox Control to the function
'Me.textCtl.BackColor = DialogColor(Me.textCtl)
'End Sub


Option Compare Database
Option Explicit
'*********** Code Start ***********
Private Type COLORSTRUC
lStructSize As Long
hwnd As Long
hInstance As Long
rgbResult As Long
lpCustColors As String
Flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Private Const CC_SOLIDCOLOR = &H80

Private Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" _
(pChoosecolor As COLORSTRUC) As Long

Public Function aDialogColor(prop As Property) As Boolean
Dim x As Long, CS As COLORSTRUC, CustColor(16) As Long

CS.lStructSize = Len(CS)
CS.hwnd = hWndAccessApp
CS.Flags = CC_SOLIDCOLOR
CS.lpCustColors = String$(16 * 4, 0)
x = ChooseColor(CS)
If x = 0 Then
' ERROR - use Default White
prop = RGB(255, 255, 255) ' White
aDialogColor = False
Exit Function
Else
' Normal processing
prop = CS.rgbResult
End If
aDialogColor = True
End Function
 
Regardless of the possabilities, I would recommend AGINST providing any such facillity. Users WILL find sone way to abuse the privellge - and YOU will 'wear it'. I have spent a (large) number of hours removing this capability from a legacy app. Users "chose" the same forecolor and backcolor for an object - then complained (rather 'loudly') that the app wouldn't display their data - and that was one of the easier ones to deal with. You wouldn't believe the squabbles between the various 'culture' factions. At least if YOU set the color scheme, you can defend YOUR selection, and not need to deal w/ the 'fashion police'.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
You brought up a good point MichaelRed. I thought about that, and I came up with a couple "solutions" (word used very lightly) to this problem. One is to only allow the user to ONLY change the background color of the form (detail section) itself. Controls will stay at the same color all the time. Of course if they chose black, all labels would be the same color as the background.....

Another solution is to do a check to see if they choose the same color for two different things. Then again, one shade off and it would pass the check.
I could check to make sure that the colors aren't TOO similar, but I think that would be more trouble then it's worth.

Thank you for bringing that up though, it's got me thinking more seriously about this now.
 
Archery1,

Thanks for the code, but I don't really understand it too well. Also, for now I only want to change the background color of the form. in the on click function I have:
Me.Detail.BackColor = DialogColor(Me.Detail)

I get a type mismatch. Also, I don't really understand what the lngRet function is for, or how/where to implement it. Same with the DialogCOlor function. Clarification would be greatly appreciated.

Jake
 
With the ability to change the colors comes the eventuality that someone will change their display settings to something that will make your application ugly at best and at worst unusable. Use the system color properties and you can avoid 99% of this nonsense. Give up the desire to have absolute control of the color scheme of your interface. For instance the only way to change a command button's color or a scroll bar's color is to write your own ocx. Who has the time to do such things just to exert control over the appearance of an interface. Make it so that if your users want to set their display appearance to "Hot Dog" (remember that?) then they will still be able to use your interface (even if it makes everyone else sick). JHall
 
Landmonster, (love that name)

I have to echo Michael's caution about doing this at all. Here's my reason in addition to the one's Michael already listed.

Let's say you design a form in a tasteful light blue color, and 90% of your users love it and keep that color. 1 user hates it and changes the color to fluorescent purple.

When that user changed the color, did your code actually change the form.backcolor property? If so, now all your users will see fluorescent purple. :-s Maq B-)
<insert witty signature here>
 
Alright, I've decided to go with the combo box with 10 or 20 colors that I picked. This way, the user still gets some choice on how the system looks (only going to change backcolor). With this solution, I only put in colors that do not conflict with any of the other colors. Thanks everybody for the help and concerns.

Jake
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top