|(Declarations)||Declarations||Declarations and private variables for the CFontDialog class.|
|Color||Property||Get the font color.|
|Flags||Property||Set the flags for the dialog.|
|Font||Property||Get a Font object representing the selections made in the Font dialog. You must use the FonInitToLogFontStruct flag for these settings to work. This property should be used with the Set syntax. For example: Set FontDialog.Font = mFont|
|FontType||Property||Get the font type.|
|Max||Property||Get the current maximum font size.|
|Min||Property||Get the current minimum font size.|
|Style||Property||Get the current font style. If the FonUseStyle flags is specified, the style combo is initialized to the value of this property. When the dialog closes, this property contains the user's selection.|
|Class_Initialize||Initialize||Set initial values.|
|Show||Method||Display the Windows font common dialog.|
|HeightToPoints||Private||Convert a font height to a font point size. The font height is measured in logical device units. Most windows API functions for dealing with fonts require the font height in logical units. This function only works correctly in the MM_TEXT mapping mode.|
|PointsToHeight||Private||Convert a font point size to a font height (in pixels). The font height is measured in logical device units. Most windows API functions for dealing with fonts require the font height in logical units. This function only works correctly in the MM_TEXT mapping mode.|
' Example of CFontDialog ' ' To try this example, do the following: ' 1. Create a new form ' 2. Add a command button named 'cmdTest' ' 3. Add a text box named 'txtTest' ' 4. Paste all the code from this example to the new form's module. ' 5. Run the form Private Sub cmdTest_Click() ' Comments: Example of using the CFontDialog class to select a font, then show the results on the form's text box Dim clsFontDialog As CFontDialog ' Initialize the class Set clsFontDialog = New CFontDialog With clsFontDialog ' Set the style for the font dialog .Flags = FonBoth Or FonEffects Or FonInitToLogFontStruct ' Preload the settings from an existing font .Font.name = txtTest.FontName .Font.Bold = txtTest.FontBold .Font.Italic = txtTest.FontItalic .Font.Size = txtTest.FontSize .Font.Underline = txtTest.FontUnderline .Color = txtTest.ForeColor ' Display the dialog. If a value was chosen, update the text box with the chosen values If .Show() Then If IsNull(txtTest) Then ' Put a value in the text box if it's empty so you can see the font settings txtTest = "Sample" End If txtTest.FontName = .Font.name txtTest.FontBold = .Font.Bold txtTest.FontItalic = .Font.Italic txtTest.FontSize = .Font.Size txtTest.FontUnderline = .Font.Underline txtTest.ForeColor = .Color Else MsgBox "User chose cancel" End If End With ' Clean up and close the class Set clsFontDialog = Nothing End Sub
The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.
Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!
Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!
"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."
Van T. Dinh, Microsoft MVP