close

改變的VFP對象的字體風格使用MSComDlg

 

首先,我們需要微軟 通用對話框控制ActiveX。跌落它到的形式,現在我們可以使用所有的FontStyle能力,從它。
像往常一樣,我們需要反映的FontStyle從我們的對象將被顯示在字體對話框在第一。你可以做它從的CommonDialog Init事件或直接從函數/方法,如果你希望能夠改變幾個對象不同的風格。
下面是例子使用幾個的對象,只要複製並粘貼到一個 PRG然後運行它。
盡情享受吧!

DEFINE CLASS form1 AS form



#Define CC_RGBINIT    0x0001

#Define CC_FULLOPEN   0x0002

#Define
CF_BOTH       0x0003   
&&屏幕和打印機字體

#Define
CF_EFFECTS    0x0100



   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

         
**



設置字體對話框,以反映最後一個對象風格

         .FontName
= toRef.FontName

         .FontSize =
toRef.FontSize

         .FontBold =
toRef.FontBold

         .FontStrikeThru =
toRef.FontStrikeThru

         .FontUnderline =
toRef.FontUnderline

         .FontItalic =
toRef.FontItalic

         
* .Color = toRef.ForeColor



         .Flags = CF_BOTH + CF_EFFECTS

         lc_OldError = on('error')

         On error ll_Cancel = .T.

         .ShowFont()

         On error &lc_OldError



         If !ll_Cancel

            
**設置的FontStyle到對象

            toRef.FontName
= .FontName

            toRef.FontSize
= .FontSize

            toRef.FontBold
= .FontBold

            toRef.FontStrikeThru
= .FontStrikeThru

            toRef.FontUnderline
= .FontUnderline

            toRef.FontItalic
= .FontItalic

            
*
toRef.ForeColor = .Color


         endif

      EndWith

   ENDPROC





   PROCEDURE ChangeColor

      LParameters toRef

      Local ll_Cancel, lc_OldError



      With ThisForm.OleControl1

         .Color = toRef.ForeColor

         .Flags = CC_RGBINIT +
CC_FULLOPEN



         ll_Cancel = .F.

         lc_OldError = on('error')

         On error ll_Cancel = .T.

         .ShowColor()

         On error &lc_OldError



         If !ll_Cancel

            toRef.ForeColor
= .Color

         endif

      EndWith

   ENDPROC





   PROCEDURE edit1.RightClick

      ThisForm.ChangeFont(This)

   ENDPROC



   PROCEDURE edit1.DblClick

      ThisForm.ChangeColor(This)

   ENDPROC





   PROCEDURE edit2.RightClick

      ThisForm.ChangeFont(This)

   ENDPROC



   PROCEDURE edit2.DblClick

      ThisForm.ChangeColor(This)

   ENDPROC





   PROCEDURE text1.RightClick

      ThisForm.ChangeFont(This)

   ENDPROC



   PROCEDURE text1.DblClick

      ThisForm.ChangeColor(This)

   ENDPROC





   PROCEDURE OleControl1.Init

      This.CancelError = .T.

   ENDPROC



ENDDEFINE

*







 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 hsiung03 的頭像
    hsiung03

    hsiung.博格 ERP軟體

    hsiung03 發表在 痞客邦 留言(0) 人氣()