Solved

Adding a Font menu to a Visual Basic 6 Project

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

932 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

12 Experts available now in Live!

Get 1:1 Help Now