Examples of font common dialog box in VB

xiaoxiao2021-03-06  112

Private Const LF_FACESIZE = 32Private Const CF_PRINTERFONTS = & H2Private Const CF_SCREENFONTS = & H1Private Const CF_BOTH = (CF_SCREENFONTS Or CF_PRINTERFONTS) Private Const CF_EFFECTS = & H100 & Private Const CF_FORCEFONTEXIST = & H10000Private Const CF_INITTOLOGFONTSTRUCT = & H40 & Private Const CF_LIMITSIZE = & H2000 & Private Const REGULAR_FONTTYPE = & H400

'Charset Constants

Private Const ANSI_CHARSET = 0Private Const ARABIC_CHARSET = 178Private Const BALTIC_CHARSET = 186Private Const CHINESEBIG5_CHARSET = 136Private Const DEFAULT_CHARSET = 1Private Const EASTEUROPE_CHARSET = 238Private Const GB2312_CHARSET = 134Private Const GREEK_CHARSET = 161Private Const HANGEUL_CHARSET = 129Private Const HEBREW_CHARSET = 177Private Const JOHAB_CHARSET = 130Private Const MAC_CHARSET = 77Private Const OEM_CHARSET = 255Private const russian_charset = 204Private const shiftjis_charset = 128private const symbol_charset = 2PRIVATET THAI_CHARSET = 222Private const Turkish_charset = 162

Private 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 As String * 31End TypePrivate Type CHOOSEFONT lStructSize As Long hwndOwner As Long 'caller's window handle hDC As Long' printer DC / IC or NULL lpLogFont As Long 'ptr. to a LOGFONT struct iPointSize As Long' 10 * size in points of selected font flags As Long 'enum. type flags rgbColors As Long 'Returned Text Color LCUSTDATA AS Long' Data Passed to Hook Fn. Lpfnhook as long 'ptr. To hook function lptemplatename as string' Custom Template Name Hinstance As L ong 'instance handle of.EXE that' contains cust. dlg. template lpszStyle As String 'return the style field here' must be LF_FACESIZE or bigger nFontType As Integer 'same value reported to the EnumFonts' call back with the extra FONTTYPE_' bits added MISSING_ALIGNMENT AS INTEGER NSIZEMIN As Long 'Minimum Pt Size ALLOWED & NSEMAX AS Long' Max Pt Size ALLOWED IF '

CF_LIMITSIZE is usedEnd TypePrivate Declare Function CHOOSEFONT Lib "comdlg32.dll" Alias ​​"ChooseFontA" _ (ByRef pChoosefont As CHOOSEFONT) As LongPrivate Sub Command1_Click () Dim cf As CHOOSEFONT, lfont As LOGFONT Dim fontname As String, ret As Long cf.flags = CF_BOTH Or CF_EFFECTS Or CF_FORCEFONTEXIST Or CF_INITTOLOGFONTSTRUCT Or CF_LIMITSIZE cf.lpLogFont = VarPtr (lfont) cf.lStructSize = LenB (cf) 'cf.lStructSize = Len (cf)' size of structure cf.hwndOwner = Form1.hWnd 'window Form1 is opening this dialog box cf.hDC = Printer.hDC 'device context of default printer (using VB's mechanism) cf.rgbColors = RGB (0, 0, 0)' black cf.nFontType = REGULAR_FONTTYPE 'regular font type ie not bold or anything cf .nSizeMin = 10 'minimum point size cf.nSizeMax = 72' maximum point size ret = CHOOSEFONT (cf) 'brings up the font dialog If ret <> 0 Then' success fontname = StrConv (lfont.lfFaceName, vbUnicode, & H 804) 'Retrieve chinese font name in english version os fontname = Left $ (fontname, InStr (1, fontname, vbNullChar) - 1)' Assign the font properties to text1 With Text1.Font .Charset = lfont.lfCharSet 'assign charset to Font .name = fontname .size = cf.ipoint text1.text = .name & ":" & .charset & ":" sc "display data in chosen font end

转载请注明原文地址:https://www.9cbs.com/read-100847.html

New Post(0)