giann
asked on
Caption of a Form
In VB4, how can I have the Caption of a Form not in upper left side (as usually), but in the middle? (I also do not like the solution to type Spaces in the Caption Properties to move the Caption to the center)
hearing...
The best way to do it is draw your own caption in the window.
Pls look for the article in MSDN
HOWTO: Draw a Custom Window Caption
ID: Q99046
This will give you enough information. But the code is in C, so you should convert it to Visual Basic
Pls look for the article in MSDN
HOWTO: Draw a Custom Window Caption
ID: Q99046
This will give you enough information. But the code is in C, so you should convert it to Visual Basic
The short answer is that there is no way to center a caption on the form without adding spaces, either at design time, or in the resize event to keep it centered.
The long answer is that you can subclass your form and draw the non client area (title bar) yourself. This has many headaches that go along with it.
The long answer is that you can subclass your form and draw the non client area (title bar) yourself. This has many headaches that go along with it.
The answer you don't want to hear is that the reason it's not easy to do this in VB is because having a window's caption left justified is a Windows GUI standard.
The drawback is: cost is too high for a little award.
ASKER
The code that R_Rajesh suggests works. It centers the form caption.
But the problem is that when I change (by right click on my screen) the windows theme in screen properties from classical windows to Windows Xp, then the Caption of the Form moves a little more right and it is not centered any more.
(Otherwise I would have no problem to type spaces)
But the problem is that when I change (by right click on my screen) the windows theme in screen properties from classical windows to Windows Xp, then the Caption of the Form moves a little more right and it is not centered any more.
(Otherwise I would have no problem to type spaces)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Well, technically, you can predict any case and make it centered. But it's really a lot to go through -- API again! There's a function, I think, called GetSystemMetrics() and it returns a bunch of information about "anything" "measureable" in Windows. You can get the size of the min/max/close buttons, do the necessary calculations, and center accordingly using spaces. No one would ever want to do that, I tell you.
You are right DeuceEE, I'm sure there is a way to correctly calculate the necessary number of spaces to center the caption.
My point was that there isn't a precise way to center the text using only the values returned from the Form.Width property combined with the width of the caption from the TextWidth() function.
Idle_Mind
My point was that there isn't a precise way to center the text using only the values returned from the Form.Width property combined with the width of the caption from the TextWidth() function.
Idle_Mind
Try this:
http://www.ostrosoft.com/vb/projects/center.asp
Cheers!
Raj