How do I find the font size of the Title Bar?

  • Thread starter Thread starter Christopher W. Douglas
  • Start date Start date
C

Christopher W. Douglas

I am developing an application in VB.NET using Visual Studio 2003. I have a
dialog box where the title may be somewhat long, so I want to resize the
window to fit the entire title. I already know to use CreateGraphics to
measure the length of the string, so my code is something like this (from
the Load event):

objGraphics = CreateGraphics()
objFont = System.Windows.Forms.SystemInformation ??????
intTextLength = cint(objGraphics.MeasureString(Text, objFont).Width)
if intTextLength > Width Then
Width = intTextLength
end if

The problem is, I can't find a simple way to get the Font size of the title
bar of the window. I already Googled for "active title bar" and found a
reference to "System.Windows.Forms.SystemInformation", but none of the
properties there seem to apply. I would think this is a straightforward
thing, to get the current user's settings for Title Bar font size, but it
eludes me. Any help would be appreciated.
 
I suspect that you would have to look it up in the registry. I do not
remember the exact key, but I suspect that it is HKEY_CURRENT_USER\Control
Panel\Desktop\WindowMetrics or one of the associated ones.

HTH

David
 
Thanks for your reply, and I will try it. However, does this make sense
that you HAVE to look in the registry to find this information? I mean, I
can get the font of a control with just txtBox.Font, or the font of the form
(labels as such) as me.Font. Why isn't there a SIMPLE means of getting the
title bar font for a form?
 
* "Christopher W. Douglas said:
I am developing an application in VB.NET using Visual Studio 2003. I have a
dialog box where the title may be somewhat long, so I want to resize the
window to fit the entire title. I already know to use CreateGraphics to
measure the length of the string, so my code is something like this (from
the Load event):

Maybe p/invoke, a VB6 sample can be found here:

<http://vbaccelerator.nuwebhost.com/tips/vba0034.htm>
 
Back
Top