First we need "Microsoft Common Dialog Control" ActiveX. Drop it into your form, now we can use all FontStyle capability from it.
As usual, we need to reflect the FontStyle from our object to be display in Font Dialog at first. You can do it from CommonDialog init event or directly from the function/method if you want to be able to change several object with different style.
Here is the example using several object, just copy and paste it into a prg then run it.
Enjoy!
Thanks to:
Chris R. Chamberlain for giving me an idea to make this FAQ
[color green]**************************************************[/color]
DEFINE CLASS form1 AS form
Top = 0
Left = 0
Height = 233
Width = 400
DoCreate = .T.
ShowTips = .T.
Caption = "Form1"
Name = "Form1"
ADD OBJECT edit1 AS editbox WITH ;
Height = 140, ;
Left = 18, ;
Value = "Right Click to change the FontStyle, " + ;
"Double Click to change Color", ;
Top = 12, ;
Width = 179, ;
Name = "Edit1"
ADD OBJECT edit2 AS editbox WITH ;
Height = 140, ;
Left = 203, ;
Value = "Right Click to change the FontStyle, " + ;
"Double Click to change Color", ;
Top = 12, ;
Width = 179, ;
Name = "Edit2"
ADD OBJECT text1 AS textbox WITH ;
Height = 23, ;
Left = 32, ;
Value = "Right Click to change the FontStyle, " + ;
"Double Click to change Color", ;
Top = 166, ;
Width = 336, ;
IntegralHeight = .T., ;
Name = "Text1"
ADD OBJECT OleControl1 AS olecontrol WITH ;
Top = 11, ;
Left = 149, ;
Height = 100, ;
Width = 100, ;
OLEClass = "MSComDlg.CommonDialog.1", ;
Name = "OleControl1"
PROCEDURE ChangeFont
LParameters toRef
Local ll_Cancel, lc_OldError
With ThisForm.OleControl1
[color green]** Set Font Dialog to reflect the last Object Style[/color]
.FontName = toRef.FontName
.FontSize = toRef.FontSize
.FontBold = toRef.FontBold
.FontStrikeThru = toRef.FontStrikeThru
.FontUnderline = toRef.FontUnderline
.FontItalic = toRef.FontItalic
[color green]* .Color = toRef.ForeColor[/color]
.Flags = CF_BOTH + CF_EFFECTS
lc_OldError = on('error')
On error ll_Cancel = .T.
.ShowFont()
On error &lc_OldError
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.