Solved

Adding a Font menu to a Visual Basic 6 Project

Posted on 2006-07-11
7
456 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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
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…

828 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