Solved

Adding a Font menu to a Visual Basic 6 Project

Posted on 2006-07-11
7
459 Views
Last Modified: 2013-12-03
I'm sure this must be a simple thing to do, but I can find nothing anywhere on how to do it! I have a project written in Visual Basic 6. I need to add a Font menu to it so that the user can select a font which will be used for subsequent text drawing into a PictureBox. Ideally the Font Menu should list every available font on the computer (just like in Microsoft Word, for example). I assume that I would need to add a "Font" menu to the form using the Menu Editor, that the code to "populate" the "Font" menu would be part of the "Form Load" code, and that I might also need to dispose of the memory used when the form is unloaded and the application is quit. Can anyone help please?
0
Comment
Question by:chazzzm
[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
7 Comments
 
LVL 10

Accepted Solution

by:
sakuya_su earned 63 total points
ID: 17088262
um the Microsoft CommonDialog control has a ShowFont which displays a Font/Size/Colour selection screen

you can read the values user choose from .FontName, .FontSize etc

so if ur control is called c1, then after user chose c1.FontName will contain the font he chose etc..
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 17088337
Use the CommonDialog control. This demonstrates how:

Private Sub Command1_Click()
    With CommonDialog1
        .FontName = Text1.Font.Name
        .FontSize = Text1.Font.Size
        .FontBold = Text1.Font.Bold
        .FontItalic = Text1.Font.Italic
        .FontUnderline = Text1.Font.Underline
        .FontStrikethru = Text1.Font.Strikethrough
    End With

    CommonDialog1.Flags = cdlCFScreenFonts
    CommonDialog1.CancelError = True
    On Error Resume Next
    CommonDialog1.ShowFont
    If Err = cdlCancel Then Exit Sub

    ' Use the dialog's properties.
    With CommonDialog1
        Text1.Font.Name = .FontName
        Text1.Font.Size = .FontSize
        Text1.Font.Bold = .FontBold
        Text1.Font.Italic = .FontItalic
        Text1.Font.Underline = .FontUnderline
        Text1.Font.Strikethrough = .FontStrikethru
    End With
End Sub
0
 
LVL 8

Expert Comment

by:kaliyugkaarjun
ID: 17088394
http://goforit.unk.edu/vb6/pt7_3.htm

in that read "3.5 Change Font Dialog"
0
 
LVL 26

Assisted Solution

by:EDDYKT
EDDYKT earned 62 total points
ID: 17090520
use can also use API to list all fonts

'in a form
Private Sub Form_Load()
    'KPD-Team 2000
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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.
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

688 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