Results 1 to 5 of 5

Thread: [RESOLVED] CommonDialog and font style

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Location
    Texas
    Posts
    164

    Resolved [RESOLVED] CommonDialog and font style

    When calling up the CommonDialog for Fonts, is there a way to NOT display the font style (bold, regular, italic, etc.)? All I want to user to be able to select a font and size.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: CommonDialog and font style

    It doesn't make any difference what it shows unless you explicitly assigned all of the selected properties. Otherwise assign only those that you need:
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        With CommonDialog1
            .ShowFont
            Label1.FontName = .FontName
            Label1.FontSize = .FontSize
        End With
    End Sub

  3. #3
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: CommonDialog and font style

    Since there is no flag that hides the Font Style combo box, you may want to disable the combo box to prevent confusing the user:

    Code:
    Option Explicit
    
    Private Declare Function EnableWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal bEnable As Long) As Long
    Private Declare Function FindWindowW Lib "user32.dll" (Optional ByVal lpClassName As Long, Optional ByVal lpWindowName As Long) As Long
    Private Declare Function GetDlgItem Lib "user32.dll" (ByVal hDlg As Long, ByVal nIDDlgItem As Long) As Long
    
    Private WithEvents Tmr As VB.Timer
    
    Private Sub cmdShowFont_Click()
        CommonDialog1.Flags = cdlCFBoth Or cdlCFNoStyleSel
    
        Set Tmr = Controls.Add("VB.Timer", "Tmr")
        Tmr.Interval = 50&
        Tmr = True
    
        CommonDialog1.ShowFont
    
        Set Tmr = Nothing
        Controls.Remove "Tmr"
    End Sub
    
    Private Sub Tmr_Timer()         'Note: Timers are blocked in the IDE by modal dialog boxes
        Const IDC_FONT_STYLE = 1137&
        Dim hWndFontDlg As Long, hWndComBox As Long
    
        hWndFontDlg = FindWindowW(StrPtr("#32770"), StrPtr("Font"))
        If hWndFontDlg Then
            hWndComBox = GetDlgItem(hWndFontDlg, IDC_FONT_STYLE)
            If hWndComBox Then
                Tmr = False
                EnableWindow hWndComBox, 0&
            End If
        End If
    End Sub
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Location
    Texas
    Posts
    164

    Re: CommonDialog and font style

    I know I can just not use the settings, but I'm more interested in not confusing the user and getting calls saying it shows all these styles but the program does not use them. I did not find any flag to turn off but was wanting to see if any other way. Obviously not, so I will just allow the user to set not only the font and size, but also the style.

  5. #5
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [RESOLVED] CommonDialog and font style

    You can, of course, replace EnableWindow with ShowWindow if you really wanted to hide the Font Style combo box.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width