************************************************** *-- Class: fontselect (c:\profiler\progs\fontselect.vcx) *-- ParentClass: form *-- BaseClass: form *-- Time Stamp: 10/02/02 12:57:02 PM * DEFINE CLASS fontselect AS form Top = -2 Left = 0 Height = 136 Width = 430 DoCreate = .T. Caption = "Please select a font and a fontsize" WindowType = 1 returnvalue = "''" startvalue = "''" cn_preprta = "''" cn_preprtb = "''" varname = "''" startvar = "''" Name = "Form1" DIMENSION gafontarray[1,1] DIMENSION gasizearray[1,1] ADD OBJECT combo1 AS combobox WITH ; RowSourceType = 5, ; RowSource = "thisform.gafontarray", ; ControlSource = "thisform.cn_preprta", ; Height = 24, ; Left = 4, ; Style = 2, ; Top = 28, ; Width = 228, ; Name = "Combo1" ADD OBJECT text1 AS textbox WITH ; BorderStyle = 0, ; Value = "This is an example of the font.", ; Height = 70, ; Left = 5, ; ReadOnly = .T., ; SpecialEffect = 1, ; TabStop = .F., ; Top = 60, ; Width = 296, ; Name = "Text1" ADD OBJECT combo2 AS combobox WITH ; RowSourceType = 5, ; RowSource = "thisform.gasizearray", ; ControlSource = "thisform.cn_preprtb", ; Height = 24, ; Left = 240, ; Style = 2, ; Top = 28, ; Width = 72, ; Name = "Combo2" ADD OBJECT command1 AS commandbutton WITH ; Top = 70, ; Left = 314, ; Height = 27, ; Width = 108, ; Caption = "Accept", ; ForeColor = RGB(255,0,0), ; Name = "Command1" ADD OBJECT command2 AS commandbutton WITH ; Top = 106, ; Left = 314, ; Height = 27, ; Width = 108, ; Caption = "Cancel", ; Name = "Command2" ADD OBJECT label1 AS label WITH ; AutoSize = .T., ; FontBold = .T., ; FontSize = 12, ; Caption = "Font Name", ; Height = 22, ; Left = 4, ; Top = 5, ; Width = 85, ; Name = "Label1" ADD OBJECT label2 AS label WITH ; AutoSize = .T., ; FontBold = .T., ; FontSize = 12, ; Caption = "Font Size", ; Height = 22, ; Left = 240, ; Top = 5, ; Width = 74, ; Name = "Label2" ADD OBJECT command3 AS commandbutton WITH ; Top = 12, ; Left = 336, ; Height = 27, ; Width = 84, ; Cancel = .T., ; Caption = "Command3", ; Enabled = .F., ; TabStop = .F., ; Visible = .F., ; Name = "Command3" PROCEDURE Load DODEFAULT() PUBLIC lcfont32alias, lnfont32recno STORE ALIAS() TO lcfont32alias STORE RECNO() TO lnfont32recno IF UPPER(TYPE('ddir'))!="U" IF FILE(ddir+'cafonts.dbf') USE (ddir+'cafonts') IN 0 ENDIF IF FILE(ddir+'casize.dbf') USE (ddir+'casize') IN 0 ENDIF ENDIF ENDPROC PROCEDURE Init *!* *--init *!* Run with code like the following: *!* varname="cn_preprt" *!* varvalue="courier new,10" *!* DO FORM font32 WITH varname, varvalue PARAMETERS varname, varvalue, formname IF UPPER(TYPE('varname'))="L" varname="" ENDIF IF UPPER(TYPE('varvalue'))="L" varvalue="" ENDIF PRIVATE icount FOR icount = 1 TO _screen.formcount IF lower(varname)="cn_preprt" IF LOWER(_screen.forms(icount).name)="frmprintersetup" varvalue=PROPER(ALLTRIM(_screen.forms(icount).txtCn_preprt.value)) ENDIF ENDIF IF lower(varname)="cn_postprt" IF LOWER(_screen.forms(icount).name)="frmprintersetup" varvalue=PROPER(ALLTRIM(_screen.forms(icount).txtCn_postprt.value)) ENDIF ENDIF ENDFOR varvalue=PROPER(ALLTRIM(varvalue)) thisform.startvalue=varvalue thisform.startvar=varname IF UPPER(TYPE('returnvalue'))="U" PUBLIC returnvalue returnvalue="" ENDIF DODEFAULT() *------Environment PUBLIC lcfont32escapeset,lcfont32onescape lcfont32escapeset='OFF' lcfont32onescape="" lcfont32escapeset=SET('ESCAPE') lcfont32onescape=ON('ESCAPE') SET ESCAPE ON ON KEY LABEL ESC _Screen.ActiveForm.Release() *------End Environment Settings *--If the cafonts table exists, use it for the 1st combo box displaying fonts PRIVATE lncount IF USED('cafonts') SELE cafonts lncount=RECCOUNT() DIMENSION thisform.gafontarray(lncount,1) COPY TO ARRAY thisform.gafontarray =ASORT(thisform.gafontarray) ELSE =AFONT(thisform.gaFontArray) ENDIF *--If the casize table exists, use it for the 2nd combo box displaying font sizes IF USED('casize') SELE casize lncount=RECCOUNT() DIMENSION thisform.gasizearray(lncount,1) COPY TO ARRAY thisform.gasizearray ELSE *--Tested code below ok *!* PRIVATE i *!* PRIVATE n *!* n=0 *!* FOR i = 6 TO 12 STEP 2 *!* n=n+1 *!* DIMENSION thisform.gasizearray(n,1) *!* thisform.gasizearray(n,1)=ALLTRIM(STR(i)) *!* IF thisform.gasizearray(n,1)="6" *!* n=n+1 *!* DIMENSION thisform.gasizearray(n,1) *!* thisform.gasizearray(n,1)="7" *!* ENDIF *!* * SELE casize *!* * APPEND BLANK *!* * REPLACE casize.csize WITH ALLTRIM(STR(i)) *!* ENDFOR *--Tested code above ok *--TCH 6/18/2002 Get font sizes 6-14 including odd sizes PRIVATE i PRIVATE n n=0 FOR i = 6 TO 14 n=n+1 DIMENSION thisform.gasizearray(n,1) thisform.gasizearray(n,1)=ALLTRIM(STR(i)) ENDFOR ENDIF IF !EMPTY(varvalue) && did we pass a font name and size like 'Courier New,12'? *--Can we locate the current selected font in the array PRIVATE gnPos gnPos = ASCAN(thisform.gaFontArray, PROPER(LEFT(varvalue,AT(',',varvalue)-1))) IF gnPos != 0 && found font passed thisform.cn_preprta=PROPER(LEFT(varvalue,AT(',',varvalue)-1)) ELSE *--Let's try to find courier new, the most often used font for selection gnPos=ASCAN(thisform.gaFontArray,'Courier New') IF gnPos!=0 && found courier new in the array thisform.cn_preprta=ALLTRIM(thisform.gaFontArray(gnPos)) ELSE && start at top of array, couldn't find courier new in array thisform.cn_preprta=thisform.gafontarray(1,1) ENDIF ENDIF *--Can we locate the current selected font size in the array gnPos = ASCAN(thisform.gaSizeArray, RIGHT(varvalue,LEN(varvalue)-(AT(',',varvalue)))) IF gnPos != 0 && found fontsize passed to form thisform.cn_preprtb=RIGHT(varvalue,LEN(varvalue)-(AT(',',varvalue))) ELSE && Let's try to find size 12, most common font size used gnPos=ASCAN(thisform.gaSizeArray, '12') IF gnPos!=0 && found fontsize 12 in fontsize array thisform.cn_preprtb=ALLTRIM(thisform.gaSizeArray(gnPos)) ELSE && couldn't find fontsize 12, start at top of font size array thisform.cn_preprtb=thisform.gasizearray(1,1) ENDIF ENDIF ELSE && font name and size was passed to form, so start at top of arrays *--Let's try to find courier new, the most often used font for selection gnPos=ASCAN(thisform.gaFontArray,'Courier New') IF gnPos!=0 && found courier new in the array thisform.cn_preprta=ALLTRIM(thisform.gaFontArray(gnPos)) ELSE && start at top of array, couldn't find courier new in array thisform.cn_preprta=thisform.gafontarray(1,1) ENDIF gnPos=ASCAN(thisform.gaSizeArray, '12') IF gnPos!=0 && found fontsize 12 in fontsize array thisform.cn_preprtb=ALLTRIM(thisform.gaSizeArray(gnPos)) ELSE && couldn't find fontsize 12, start at top of font size array thisform.cn_preprtb=thisform.gasizearray(1,1) ENDIF ENDIF *--Display the font in the textbox thisform.text1.click() ENDPROC PROCEDURE Release IF LOWER(ALLTRIM(thisform.varname))="cn_preprt" cn_preprt=thisform.returnvalue ENDIF IF LOWER(ALLTRIM(thisform.varname))="cn_postprt" cn_postprt=thisform.returnvalue ENDIF returnvalue=thisform.returnvalue returntype=varname IF USED('cafonts') USE IN cafonts ENDIF IF USED('casize') USE IN casize ENDIF IF LEN(ALLTRIM(lcfont32alias))>0 IF UPPER(ALIAS())<>UPPER(lcfont32alias) SELECT (lcfont32alias) IF RECNO() <> lnfont32recno goto (lnfont32recno) ENDIF ENDIF ENDIF RELEASE lcfont32alias,lnfont32recno ON KEY LABEL ESC &lcfont32onescape SET ESCAPE &lcfont32escapeset RELEASE lcfont32escapeset,lcfont32onescape DODEFAULT() ENDPROC PROCEDURE Unload DODEFAULT() IF LOWER(ALLTRIM(varname))="cn_preprt" IF LEN(ALLTRIM(thisform.returnvalue))>0.and.thisform.returnvalue!="''" cn_preprt=thisform.returnvalue RETURN cn_preprt ELSE RETURN ENDIF ENDIF IF LOWER(ALLTRIM(varname))="cn_postprt" IF LEN(ALLTRIM(thisform.returnvalue))>0.and.thisform.returnvalue!="''" cn_postprt=thisform.returnvalue RETURN cn_postprt ELSE RETURN ENDIF ENDIF IF LEN(ALLTRIM(returnvalue))>0.and.returnvalue!="''" RETURN returnvalue ELSE RETURN ENDIF ENDPROC PROCEDURE combo1.Valid DODEFAULT() THISFORM.text1.click() ENDPROC PROCEDURE text1.Click THIS.value="This is an example of the font "+ALLTRIM(thisform.combo1.value)+". Size "+ALLTRIM(thisform.combo2.value) This.fontname=ALLTRIM(thisform.combo1.value) This.fontsize=VAL(ALLTRIM(thisform.combo2.value)) thisform.refresh() DODEFAULT() ENDPROC PROCEDURE combo2.Valid DODEFAULT() THISFORM.text1.click() ENDPROC PROCEDURE command1.Click thisform.returnvalue=ALLTRIM(thisform.cn_preprta)+","+ALLTRIM(thisform.cn_preprtb) THISFORM.RELEASE() ENDPROC PROCEDURE command2.Click thisform.returnvalue=thisform.startvalue THISFORM.RELEASE() ENDPROC ENDDEFINE * *-- EndDefine: fontselect **************************************************>Have you guy seen that when you want to change the font of a specific part of the text you just have to select it and then go to the nice combobox wich contains all the fonts name and the preview of'em?