Changing form titlebar color

I know how to change the system colors so that ALL the titlebars of all the windows change color using a Windows API.  My question is how can I make JUST ONE form change?  

For example, I create a new project and have a form called Form1.  The active window titlebar color is BLUE.  How can I change JUST Form1's titlebar color to say GREEN?

Please provide sample code.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can't do this unless you draw your own title bar for the form.

Why do this? The user has chosen a colour scheme for their desktop. Respect that.
caraf_g is right. The title bar is part of the desktop and not your application. Thus there is no programmatic control for it. This is not a bug, but a feature. You also can't change the font without changing the entire desktop's appearance.

Check this out... 

The guy that posted it didn't post all of the code, but you could email'm for it....

The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

HATCHETAuthor Commented:
caraf_g   and   mark2150,

I'm sorry, I should have been more specific as to what I needed this for.  Maybe would have gotten people off to a better start.

I'm using some code I found to subclass a form and gradiate it's titlebar.  I've managed to fix a lot of bugs in the code that prevent it from drawing the gradient correctly, however there's one last thing I'm stumpted on.  I can make it draw a 2 color gradient on the titlebar given 2 colors.  What it does is draws the gradient over the existing titlebar, draws the icon in the right place, draws the text in the right place and I'm done.  The problem occurs if your second color (the color on the right side) is different from the default windows colors for the titlebar.  Say I specify RED for the start color on the left and GREEN for the end color on the right.  If the default active color for windows titlebars is BLUE, then you'll see gradiation from RED over to GREEN then the control box containing the MIN/MAX/CLOSE buttons is BLUE and doesn't match at all.

If the fix for this is drawing over that area, that's kewl... but I need sample code to head me in the right direction.  Or is there another way to do what I'm trying to do?  I was figuring that if I changed the color of THAT form to the end color, it would match and look right.  

You're right, I don't want to mess with the user's colors and I won't do that.  Need something that's form specific.



I checked out the page you specified and the code is chopped in half and I can't see how to get in touch with the guy.  His web page link is PATHETIC!  Any ideas?


this sample will cover the titlebar with a bitmap hope it helps plus i need the points

'Windows global API
Option Explicit
DefLng A-Z
Declare Function LoadBitmap Lib "user32" Alias "LoadBitmapA" (ByVal hInstance As Long, ByVal lpBitmapName As String) As Long

Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Declare Function CloseClipboard Lib "user32" () As Long
Declare Function EmptyClipboard Lib "user32" () As Long
Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
Public Const CF_BITMAP = 2
Public Const LR_LOADMAP3DCOLORS = &H1000
Public Const LR_LOADFROMFILE = &H10
Public Const IMAGE_BITMAP = 0

'source code
Public Sub MakeFileTrans(ImgPic As Object, ByVal FileName As String)
'You'll need to add an NT 4.0 procedure
Dim BitMapLong As Long
Dim TempLong As Long
TempLong = OpenClipboard(0)
TempLong = EmptyClipboard()
BitMapLong = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, _
TempLong = SetClipboardData(CF_BITMAP, BitMapLong)
TempLong = CloseClipboard()

Set ImgPic.Picture = Clipboard.GetData(vbCFBitmap)
Clipboard.SetText ""

End Sub
HATCHETAuthor Commented:

Either you didn't read the question or you don't know jack about Visual Basic programming.  The code you gave me was to clear the clipboard, load a specified image into a PictureBox control, then store the picture in your clipboard.  There's NOTHING in your code about anything to do with the titlebar of the form!  And the way you worked with the clipboard is all thru the Win32 API... next time look into the "Clipboard" object in VB.

However, I did find it interesting that it made certain colors in the loaded image trasparent even though it was a bitmap.

Nevertheless... I'm rejecting your answer in hope that someone has an answer... though I fear no one will and I'll have to JimmyRig the code or give up on my idea.

Oh wel, Cea la vi.

I thought the guy had an email address there... Oh well, you could leave a message on that thread and invite him here...

Turn off the controls on the title bar and draw your own stuff up there instead of using the standard _ [] X buttons.

But in gods name why are you trying to break the GUI paradigm? Leave the outer frame stuff as the desktop generates it and your app will then "look and feel" like a standard windows app. This will also protect you from obsolesence as if the OS changes the baseline GUI, your program will change with it instead of being out of sync.

Overriding the standard GUI is *NOT* a good idea. For all it's warts the user community is *used* to the standard "look and feel" - making your app *different* steepens the user learning curve.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
try implement source code from:

Thats good one.
HATCHETAuthor Commented:

That's an interesting way of doing it, but not the best because the gradient still does not cover the control area and the gradient does not resize with the form.  I can see a benefit to that though... if you want to put a company logo in the titlebar or something... that would be great.

I've been doing some searching and the simplest way to do gradients that I've found is a control called ARFormExtender.  Just put it on the form, set the Gradient Titlebar property to TRUE, and you're done!  Seems to do a good job with the gradient and NO CODING REQUIRED!  Yee haa.

Anyways... I'm going to give it one last shot with mark2150's idea and remove the control box, then add my own system drop downs to emulate the control box with gradient effects.  I really don't think it will work but it's worth a shot.  In the meanwhile... he's made a good point about the standard Windows GUI and I'll stick to the GetSysColor(COLOR_ACTIVECAPTION) and GetSysColor(COLOR_INACTIVECAPTION) for the standard active and inactive colors on the right side.  That way the color always blends into the control box colors but allows for the initial color to be customized.

Thanks again for all the help and input on this one.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.