Results 1 to 5 of 5

Thread: How can i set font without commondialog???

  1. #1

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    How can i put a new font to a label. I try that
    label1.font = "c:\windows\fonts\?????.TTF"
    But it does'nt work, the font change , but just once
    and whatever font i put it's always the same!

  2. #2
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    Code:
    MyLabel.Font.Name = "Arial"
    Simple and easy.

  3. #3
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    The decimal point is optional.
    Uppercase and lowercase characters are the same, meaning that "Arial" equals "arial".
    Code:
    MyLabel.FontName = "Arial"

  4. #4
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    If you want to let the user choose what font to use, just load the fonts into a listbox/combo box, then set the font using text1.font = list1.text or combo1.text. The code to load the fonts into a listbox is below.
    Code:
    Private Sub Form_Load()
    Dim intCount
    For intCount = 1 To Screen.FontCount
         List1.AddItem Screen.Fonts(intCount)
    Next intCount
    End Sub
    <removed by admin>

  5. #5
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    You can also use the EnumFonts API:
    Code:
    'in a form
    Private Sub Form_Load()
        Me.AutoRedraw = True
        EnumFonts Me.hDC, vbNullString, AddressOf EnumFontProc, 0
    End Sub
    'in a module
    Private Const LF_FACESIZE = 32
    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(LF_FACESIZE) As Byte
    End Type
    Declare Function EnumFonts Lib "gdi32" Alias "EnumFontsA" (ByVal hDC As Long, ByVal lpsz As String, ByVal lpFontEnumProc As Long, ByVal lParam As Long) As Long
    Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
    Function EnumFontProc(ByVal lplf As Long, ByVal lptm As Long, ByVal dwType As Long, ByVal lpData As Long) As Long
        Dim LF As LOGFONT, FontName As String, ZeroPos As Long
        CopyMemory LF, ByVal lplf, LenB(LF)
        FontName = StrConv(LF.lfFaceName, vbUnicode)
        ZeroPos = InStr(1, FontName, Chr$(0))
        If ZeroPos > 0 Then FontName = Left$(FontName, ZeroPos - 1)
        Form1.Print FontName
        EnumFontProc = 1
    End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width