locked
Please help To Change the font size of the titlebar RRS feed

  • Question

  • Hello,

    I've changed the Font of the title bar of the form through "systemparametersinfo" parameters. n now i want to change the font size.


    But in the case of multilingual fonts the display changes coz the font size is different for different languages.

    can u help me to change the font size of the title bar?????
    the code to change the font of the title bar as follows :





    Private Type LOGFONT
    lfHeight As Long
    lfWidth As Long
    lfEscapement As Long
    lfOrientation As Long
    lfWeight As Long
    lfItalic As Byte
    lfUnderline As Byte
    lfStrikeOut As Byte
    lfCharSet As Byte
    lfOutPrecision As Byte
    lfClipPrecision As Byte
    lfQuality As Byte
    lfPitchAndFamily As Byte
    lfFaceName(1 To 32) As Byte
    End Type


    Private Type NONCLIENTMETRICS
    cbSize As Long
    iBorderWidth As Long
    iScrollWidth As Long
    iScrollHeight As Long
    iCaptionWidth As Long
    iCaptionHeight As Long
    lfCaptionFont As LOGFONT
    iSMCaptionWidth As Long
    iSMCaptionHeight As Long
    lfSMCaptionFont As LOGFONT
    iMenuWidth As Long
    iMenuHeight As Long
    lfMenuFont As LOGFONT
    lfStatusFont As LOGFONT
    lfMessageFont As LOGFONT
    End Type

    Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As NONCLIENTMETRICS, ByVal fuWinIni As Long) As Long
    Private Declare Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lf As LOGFONT) As Long

    Dim ncm As NONCLIENTMETRICS 'NONCLIENTMETRICS to change
    Dim Orincm As NONCLIENTMETRICS 'NONCLIENTMETRICS to replace original
    Dim Returned As Long
    Dim lf As LOGFONT
    Dim hFont As Long


    Private Sub Combo1_Click()

    Dim i As Integer
    ncm.cbSize = Len(ncm)

    Returned = SystemParametersInfo(41, 0, ncm, 0) 'get the system NONCLIENTMETRICS
    Orincm = ncm 'store the value of system NONCLIENTMETRICS to use later
    'now to change the font name
    'other functions can be used to change t
    ' he font name
    'but for simplicity i have used asc() &
    ' mid()


    For i = 1 To Len(Combo1.Text) 'use ncm.lfMenuFont.lfFacename(i) to change menu font
    ncm.lfMessageFont.lfFaceName(i) = Asc(Mid(Combo1.Text, i, 1))
    ncm.lfCaptionFont.lfFaceName(i) = Asc(Mid(Combo1.Text, i, 1))
    Next i
    ncm.lfMessageFont.lfFaceName(i) = 0 'add null at the end of font name
    ncm.lfCaptionFont.lfFaceName(i) = 0
    Returned = SystemParametersInfo(42, 0, ncm, &H1 Or &H2) 'remove &H2 if you don't want to affect all the open windows

    lf.lfHeight = 24 ' character height in pixels
    lf.lfWidth = 12 ' character width in pixels
    lf.lfEscapement = 0 ' orientation of next character
    lf.lfOrientation = 0 ' orientation of first character
    lf.lfWeight = 400 ' normal thickness
    lf.lfItalic = False ' not italic characters
    lf.lfUnderline = True ' not underlined characters
    lf.lfStrikeOut = False ' not strikeout characters
    lf.lfCharSet = 255 ' OEM character set
    lf.lfOutPrecision = 0 ' default output precision
    lf.lfClipPrecision = 0 ' default clipping precision
    lf.lfQuality = 0 ' default scaling quality
    lf.lfPitchAndFamily = 64 ' default pitch, script font family

    hFont = CreateFontIndirect(lf)
    MsgBox hFont
    MsgBox "Message & Caption Font Changed to " & Combo1.Text, vbOKOnly, "Amit"
    ' Returned = SystemParametersInfo(42, 0, Orincm, &H1 Or &H2) 'replace original font
    ' MsgBox "Message & Caption Font Replaced to " & StrConv(Orincm.lfCaptionFont.lfFaceName, vbUnicode), vbOKOnly, "Amit"


    '
    End Sub



    Private Sub Form_Load()

    ' Heres a very simple code to change the
    ' system
    ' NONCLIENTMETRICS like the the window t
    ' itle font,
    ' the message font,menu font using VB. Y
    ' ou can also change
    ' other elements like status font etc
    ' in your window only or all the open wi
    ' ndows
    ' like PLUS! or display settings (appear
    ' ance)
    ' also it is possible to underline, stri
    ' kethru fonts in
    ' your window with this code. This code
    ' is very useful
    ' if you are coding a multi-lingual soft
    ' ware.
    ' For more info and more free code send
    ' e-mail.
    '
    ' email - vengs_amit@yahoo.com

    Dim i As Integer
    Show
    ' to flood the combo box with first 10 f
    ' onts


    For i = 1 To 200 ' or use For i = 1 To Screen.FontCount to flood all the fonts in your pc
    Combo1.AddItem Screen.Fonts(i)
    Next i
    End Sub

    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Returned = SystemParametersInfo(42, 0, Orincm, &H1 Or &H2) 'replace original font
    MsgBox "Message & Caption Font Replaced to " & StrConv(Orincm.lfCaptionFont.lfFaceName, vbUnicode), vbOKOnly, "Amit"

    End Sub

    Private Sub mnuExit_Click()
    Returned = SystemParametersInfo(42, 0, Orincm, &H1 Or &H2) 'replace original font
    MsgBox "Message & Caption Font Replaced to " & StrConv(Orincm.lfCaptionFont.lfFaceName, vbUnicode), vbOKOnly, "Amit"
    End

    End Sub

    Wednesday, May 16, 2007 11:16 AM

Answers

  • Amit Vengurlekar,

     

    1. Here's an example form that implements a custom TitleBar.  One issue is that the Text property can't be used and therefore the TaskBar button has no caption.  You could change the borderstyle to none and draw the entire form image yourself if you want to use the Text property.

     

    Please read the following thread on the custom title bar, I hope that can help you with the problem:

     

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=561705&SiteId=1

     

    2. If you’re using .NET 3.0 you can use the SystemParameters static class in the System.Windows assembly to determine the caption height and border width. If you’re using .NET 2.0 then you need to P/Invoke the SystemParametersInfo function to retrieve the NONCLIENTMETRICS structure to get the same information.

     

    Please open the following link for further information on the SystemParametersInfo function:

     

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1237410&SiteId=1

     

     

    Tuesday, May 22, 2007 2:26 AM