?
Solved

Caption of a Form

Posted on 2003-11-14
10
Medium Priority
?
406 Views
Last Modified: 2010-05-01
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)
0
Comment
Question by:giann
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 24

Expert Comment

by:R_Rajesh
ID: 9748911
Hi giann,

Try this:
http://www.ostrosoft.com/vb/projects/center.asp

Cheers!

Raj
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9749372
hearing...
0
 
LVL 3

Expert Comment

by:Basker
ID: 9749404
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

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 9749421
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.
0
 
LVL 9

Expert Comment

by:dancebert
ID: 9750157
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.  
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9750238
The drawback is: cost is too high for a little award.
0
 

Author Comment

by:giann
ID: 9750244
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)
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 375 total points
ID: 9750297
The reason for this is that the code makes a guess as to how big the control box on the left, and the min/max/close buttons on the right are, by using the hard coded number 1300.

If WindowState <> vbMinimized Then
    If Width < iCap + 1300 Then Width = (iCap + 1300)
        Caption = String((Width - (iCap + 1300)) / (2 * i), " ") & txt
End If

When you change themes, the actual size of these controls changes and the code breaks.  In fact, if you take out the min/max buttons without changing themes the centering will be off.

The point is, there is no way to center the text exactly under all conditions.

Idle_Mind
0
 
LVL 1

Expert Comment

by:DeuceEE
ID: 9752387
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.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 9753175
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
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question