|
-
May 21st, 2013, 06:17 PM
#1
Thread Starter
Addicted Member
[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.
-
May 21st, 2013, 06:23 PM
#2
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
-
May 22nd, 2013, 03:51 AM
#3
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)
-
May 22nd, 2013, 11:39 AM
#4
Thread Starter
Addicted Member
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.
-
May 22nd, 2013, 11:55 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|