change colour in title of userform

J

Jules

Is it possible to change the background colour of the title in a vba user
form (the one that defaults to UserForm1 when you create a new userform)? I
know how to change the colours of the form itself and of any text boxes etc.
placed on the form but not the title.

thanks,
 
D

Doug Robbins - Word MVP

That is a Windows setting that can be changed by right clicking on the
desktop and selecting properties and then going to the Appearance tab. Any
change that you make there however will apply to all dialog boxes, etc.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
R

Russ

Jules,
I played around with this code in a userform to change the titlebar color of
the form. As long as you show a userform in its default modal mode (meaning
no other windows can be selected) and you set the default color values back
before hiding or unloading the form, you might find this code useful.

Paste this part in the (Declarations) section of the test userform code:
----------------------------------------
Option Explicit
Private Declare Function GetSysColor Lib "user32.dll" ( _
ByVal nIndex As Long) As Long
Private Declare Function SetSysColors Lib "user32.dll" ( _
ByVal nChanges As Long, _
ByRef lpSysColor As Long, _
ByRef lpColorValues As Long) As Long
Const COLOR_ACTIVECAPTION As Long = 2
Const COLOR_GRADIENTACTIVECAPTION As Long = 27
Const COLOR_CAPTIONTEXT As Long = 9
Dim myCOLOR_CAPTIONTEXT As Long, myCOLOR_ACTIVECAPTION As Long
Dim myCOLOR_GRADIENTACTIVECAPTION As Long
-----------------------------------------
Paste this in main userform module after creating two command buttons on the
test userform:
-----------------------------------------

Private Sub CommandButton1_Click()
Dim lngReturn As Long
myCOLOR_CAPTIONTEXT = GetSysColor(COLOR_CAPTIONTEXT)
myCOLOR_ACTIVECAPTION = GetSysColor(COLOR_ACTIVECAPTION)
myCOLOR_GRADIENTACTIVECAPTION = GetSysColor(COLOR_GRADIENTACTIVECAPTION)

lngReturn = SetSysColors(1, COLOR_CAPTIONTEXT, &HC0FFC0) 'Hex values for
the primary colors
lngReturn = SetSysColors(1, COLOR_ACTIVECAPTION, vbWhite)
lngReturn = SetSysColors(1, COLOR_GRADIENTACTIVECAPTION, vbRed)
End Sub

Private Sub CommandButton2_Click()
Dim lngReturn As Long

lngReturn = SetSysColors(1, COLOR_CAPTIONTEXT, myCOLOR_CAPTIONTEXT)
lngReturn = SetSysColors(1, COLOR_ACTIVECAPTION, myCOLOR_ACTIVECAPTION)
lngReturn = SetSysColors(1, COLOR_GRADIENTACTIVECAPTION,
myCOLOR_GRADIENTACTIVECAPTION)
End Sub
 
K

Karl E. Peterson

Russ said:
Jules,
I played around with this code in a userform to change the titlebar color of
the form.

That code actually changes the titlebar color of *any* window that has the
foreground, right?
As long as you show a userform in its default modal mode (meaning
no other windows can be selected)

That's not system modal, though, right? I mean, another app could still steal the
foreground, or the user could Alt-Tab to another app, or yours could crash leaving
another app in the foreground, or ..., or ..., or ...?
and you set the default color values back

And if you don't?

Not trying to be antagonistic, here. Just recalling a few hard-learned lessons.
 
R

Russ

Karl,
I do concede to a master like you. I am familiar with some of your previous
efforts.
That code actually changes the titlebar color of *any* window that has the
foreground, right?
Yes, any window that is active or activated subsequently.
That's not system modal, though, right? I mean, another app could still steal
the
foreground, or the user could Alt-Tab to another app, or yours could crash
leaving
another app in the foreground, or ..., or ..., or ...?
Yes, the system could still pop up a window outside of Word. And the
system's window titlebar would be changed.
And ..., or ...,-- those too.
And if you don't?

Not trying to be antagonistic, here. Just recalling a few hard-learned
lessons.
If you do, all previously changed windows, even those that accidentally pop
up before, will change back to normal, when selected again.

If you don't; or, since I didn't have code in case you selected button2
before button1, then you would have to go back and right click on the
Windows Desktop, select Properties...Appearance and select a theme that you
had before or if you restart Windows, I believe, it will reset back to what
you had before.
Nothing permanent, but I agree, that one must cover all bases to avoid
leaving a unwitting user perplexed.
I couldn't find a way yet to get the current active windows handle (easy)
and adjust its Caption (Titlebar) background only (hard, because it probably
involves bitmap coloring of regions, etc.).
 
K

Karl E. Peterson

Hi Russ --
I do concede to a master like you. I am familiar with some of your previous
efforts.

I misunderestimate stuff all the time. We're all learning, all the time.
Hopefully. said:
Yes, any window that is active or activated subsequently.

Really good way to irritate users.
If you do, all previously changed windows, even those that accidentally pop
up before, will change back to normal, when selected again.

If you don't; or, since I didn't have code in case you selected button2
before button1, then you would have to go back and right click on the
Windows Desktop, select Properties...Appearance and select a theme that you
had before or if you restart Windows, I believe, it will reset back to what
you had before.

Really good way to irritate users. <G> Stuff happens. Crashes, even.

This illustrates why in the general VB groups it's exceedingly common to advise
folks to *not* mess with universal user settings. Not if they don't want their
software uninstalled, anyway.
Nothing permanent, but I agree, that one must cover all bases to avoid
leaving a unwitting user perplexed.

Can't be done.
I couldn't find a way yet to get the current active windows handle (easy)
and adjust its Caption (Titlebar) background only (hard, because it probably
involves bitmap coloring of regions, etc.).

It's a royal PITA, really. And Microsoft is doing to the standard UI what the US
Mint is doing to the currency -- making it exceedingly difficult to reproduce. I
gave a link earlier, offering hints on how to consider proceeding. Best bet is to
tell the client you got better things to do with your life. <g>

Thanks... Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top