Solved

Adding a Font menu to a Visual Basic 6 Project

Posted on 2006-07-11
7
452 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now