VB icon

How to use the common dialog control

Email
Submitted on: 1/1/2015 11:11:00 AM
By: Found on the World Wide Web (from psc cd)  
Level: Not Given
User Rating: By 4 Users
Compatibility: VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 376
 
     Use of 3 types of common dialog boxes:1: choose printer, 2: choose font, 3: choose color. http://137.56.41.168:2080/VisualBasicSource/vb4usecommondialog.txt
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: How to use the common dialog control
' Description:Use of 3 types of common dialog boxes:1: choose printer, 2: choose font, 3: choose color. http://137.56.41.168:2080/VisualBasicSource/vb4usecommondialog.txt
' By: Found on the World Wide Web (from psc cd)
'**************************************

'1: choose printer
Public Sub ChoosePrinter
Const ErrCancel = 32755
CommonDialog1.CancelError = True
On Error GoTo errorPrinter
CommonDialog1.Flags = 64
'see the Help on Flags Properties (Print Dialog)
CommonDialog1.ShowPrinter
CommonDialog1.PrinterDefault = False
Exit Sub
errorPrinter:
If Err = ErrCancel Then Exit Sub Else Resume
End Sub
'2: choose font
Global vScreenFont, vScreenFontSize
Public Sub ChooseFont()
CommonDialog1.Flags = cdlCFScreenFonts
'see the Help on Flags Properties (Font Dialog)
CommonDialog1.ShowFont
vScreenFont = CommonDialog1.FontName
vScreenFontSize = CommonDialog1.FontSize
Call ChangeFont(Form1)
End Sub
Public Sub ChangeFont(X As Form)
Dim Control
For Each Control In X.Controls
If TypeOf Control Is Label Or _
TypeOf Control Is TextBox Or _
TypeOf Control Is CommandButton Or _
TypeOf Control Is ComboBox Or _
TypeOf Control Is ListBox Or _
TypeOf Control Is CheckBox Then
Control.Font = vScreenFont
Control.FontSize = vScreenFontSize
End If
Next Control
End Sub
'3: choose color
Global vColor
Public Sub ChooseColor
CommonDialog1.Flags = &H1& Or &H4&
'see the Help on Flags Properties (Color Dialog)
CommonDialog1.ShowColor
vColor = CommonDialog1.Color
'if you want to convert the color to hex use 
'MsgBox Convert2Hex(vColor)
'if you want to repaint youre background use
'Call ChangeColor(X as Form)
End Sub
Public Sub ChangeColor(X As Form)
Dim Control
X.BackColor = vColor
For Each Control In X.Controls
If TypeOf Control Is Label Or _
TypeOf Control Is TextBox Or _
TypeOf Control Is CommandButton Or _
TypeOf Control Is ComboBox Or _
TypeOf Control Is ListBox Or _
TypeOf Control Is CheckBox Then
Control.BackColor = vColor
End If
Next Control
End Sub
Public Function Convert2Hex(color) as String
	Dim RedValue, GreenValue, BlueValue
RedValue = (color And &HFF&)
GreenValue = (color And &HFF00&) \ 256
BlueValue = (color And &HFF0000) \ 65536
Convert2Hex = Format(Hex(RedValue) & Hex(GreenValue) & Hex(BlueValue), "000000")
End Function


Other 14 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.