Improved effect of the "llEmptyCells" parameter
(See test5.prg)
1. Detect the data type of the column from the first non-empty cell of each column
2. Preserve values when a column contains mixed values (don't loose values)
3. Detect columns after the rightmost continue column, from the point of view of the first imported row
Download link
ImportFromXlsx 2.2
Related posts
http://praisachion.blogspot.com/2016/06/inspectpptx-10.html
http://praisachion.blogspot.com/2016/06/inspectdocx-10.html
MSOffice -> DBF
http://praisachion.blogspot.com/2017/08/importfromxlsx-40.html
http://praisachion.blogspot.com/2017/06/append-from-xlsx-30.html
http://praisachion.blogspot.com/2016/08/importfromxlsx-34.html
http://praisachion.blogspot.com/2016/08/importfromxlsx-33.html
http://praisachion.blogspot.com/2016/06/importfromxlsx-32-appendfromxlsx-21.html
http://praisachion.blogspot.com/2016/06/appendfrompptx-10.html
http://praisachion.blogspot.com/2016/06/appendfromdocx-21.html
http://praisachion.blogspot.com/2016/06/importfromdocx-31.html
http://praisachion.blogspot.com/2016/06/importfrompptx-11.html
http://praisachion.blogspot.com/2016/06/importfromxlsx-31.html
http://praisachion.blogspot.com/2016/06/importfrompptx-10.html
http://praisachion.blogspot.com/2016/06/importfromdocx-30.html
http://praisachion.blogspot.com/2016/05/importfromxlsx-22.html
http://praisachion.blogspot.com/2016/02/import-dbf-from-msoffice-2007-xlsx-docx.html
http://praisachion.blogspot.com/2016/01/importfromdocx-20.html
http://praisachion.blogspot.com/2016/01/appendfromdocx-20.html
http://praisachion.blogspot.com/2016/01/importfromxlsx-13.html
http://praisachion.blogspot.com/2016/01/appendfromxlsx-20.html
http://praisachion.blogspot.com/2015/12/appendfromxlsx-15.html
http://praisachion.blogspot.com/2015/11/importfromxlsx-13.html
http://praisachion.blogspot.com/2015/09/importfromxlsx-12.html
http://praisachion.blogspot.com/2015/09/appendfromxlsx-14.html
http://praisachion.blogspot.com/2015/09/appendfromnxlsx-13.html
http://praisachion.blogspot.com/2015/08/importfromxlsx-11.html
http://praisachion.blogspot.com/2015/07/import-from-xlsx.html
http://praisachion.blogspot.com/2015/07/insert-from-focx.html
http://praisachion.blogspot.com/2015/06/append-from-docx.html
DBF -> MSOffice
Dbf2Xlsx6 4.2 (VFP6)
http://praisachion.blogspot.com/2017/04/export-dbf-to-excel-2007.html
http://praisachion.blogspot.com/2017/01/export-dbf-to-msexcel-xlsx.html
http://praisachion.blogspot.com/2017/01/export-dbf-to-mspowerpoin-pptx.html
http://praisachion.blogspot.com/2017/01/export-dbf-to-msword-docx.html
http://praisachion.blogspot.com/2016/11/export-to-xlsx.html
http://praisachion.blogspot.com/2016/11/export-to-pptx.html
http://praisachion.blogspot.com/2016/11/export-to-docx.html
http://praisachion.blogspot.com/2016/11/export-from-vfp6-to-msoffice-docx-pptx.html
http://praisachion.blogspot.com/2016/09/copytoxlsx6-10.html
http://praisachion.blogspot.com/2016/01/export-dbf-to-msoffice-2007-xlsx-docx_24.html
http://praisachion.blogspot.com/2016/01/export-dbf-to-msoffice-2007-xlsx-docx.html
http://praisachion.blogspot.com/2016/01/exporttopptx-20.html
http://praisachion.blogspot.com/2016/01/exporttodocx-20.html
http://praisachion.blogspot.com/2016/01/copytopptx-20.html
http://praisachion.blogspot.com/2016/01/exporttoxlsx-20.html
http://praisachion.blogspot.com/2016/01/copytoxlsx-30.html
http://praisachion.blogspot.com/2015/12/exporttoxlsx-19-class.html
http://praisachion.blogspot.com/2015/12/copytoxlsx-210-procedure.html
http://praisachion.blogspot.com/2015/12/exporttoxlsx-18-class.html
http://praisachion.blogspot.com/2015/12/copytoxlsx-29.html
http://praisachion.blogspot.com/2015/02/export-pptx-13.html
http://praisachion.blogspot.com/2015/01/copytodocx-12.html
http://praisachion.blogspot.com/2015/01/exportdocx-1.html
OOffice -> DBF
http://praisachion.blogspot.com/2016/11/import-from-openoffice-libreoffice-for.html
http://praisachion.blogspot.com/2016/09/importfromoowrtext-10.html
http://praisachion.blogspot.com/2016/09/importfromooffice-1o.html
http://praisachion.blogspot.com/2016/08/importfromoocalc.html
DBF -> OOffice
http://praisachion.blogspot.com/2016/09/export-dbf-to-openoffice-libreoffice_52.html
http://praisachion.blogspot.com/2016/09/export-dbf-to-openoffice-libreoffice_16.html
http://praisachion.blogspot.com/2016/09/copy-to-ods-10-openoffice-calc.html
http://praisachion.blogspot.com/2016/09/export-dbf-to-openoffice-libreoffice.html
http://praisachion.blogspot.com/2016/09/copy-to-odt-10.html
Faceți căutări pe acest blog
miercuri, 25 mai 2016
marți, 17 mai 2016
Resizer class v.2.0
Resizer and Zooming classes Version 2.0
New behaviour
- stop resizing objects by changing one property (lresize)
- restore the form in it's original state
- do not resize grid's component objects (columns a.s.o) by changing one property (lgrid)
1. MyResize is a custom-based class
Just drop an instance to your form.
The class will bind it's DoResize1() method to the form's Resize event, and the Resize() event of each column of every grid to myresize()
Object members:
- myCol
Collection
Public
Contains fontsize for each object, columns width for every grid, rowheight and headerheight for every grid. Used as a basis to calculte the corresponding new values of the same properties
- myDefa
Collection
Public
Contains fontsize, position and dimension for each object, rowheight and headerheight for every grid. Used to restore the form in its initial state
Properties:
- lgrid
Logical
Public
.T. (default) the grid's columns width, row and header height and fontsize will be also changed (scaled accordingly)
.F. only the grid's height and width will be changed
- lResize
Logical
Public
.T. when the form changes its dimensions, the objects are scaled
.F.only the form changes dimensions, objects remains untouched
- lScan Logical
Public
.F. (default) the form's object wasn't yet scanned. They will be processed at the first changing in form's dimensions, and lScan will become .T.
.T. the form's object's were processed
When lgrid = .T. and the user manually change the width of some grid's column, then lScan become .F.
- lScanD
Logical
Public
.F. (default) the form's object wasn't yet scanned. They will be processed at the first changing in form's dimensions, and lScanD will become .T.
.T. the form's object's were processed
used to store the initial state of the form (dimensions, positions and fontsize of every object)
- nAmount
Numeric
Public
1 (= 100% default) the scale factor for width
- nAmountH
Numeric
Public
1 (= 100% default) the scale factor for height
Methods:
- Init
Bind the Resize() event of the form to DoResize1() method
- lResize_assign
Public
- If lResize, bind the Resize() event of the form to DoResize1() method, otherwise unbinde them
- If Not lResize and lScan, call DoStopResizing()
- myresize
Public
- set lScan = .F.
- binded to each grid column's Resize() event (when lgrid = .T.)
- DoCollect1 Public
- If Not lScand and MyDefa collection is empty Collects the current fontsize, position and dimension of form's objects and store them to MyDefa collection
Call DoCollectD()
- If lResize = .T. Collects the current fontsize, position and dimension of form's objects and store them to MyCol collection
Depending on the value of the lGrid property, calls DoCollect(), respectivelly DoCollectG()
- If lResize = .F. clear the Anchor property of every object
Call DoStopResizing()
- DoCollect Public
Recursive procedure to get and store fontsize, position and dimension of form's objects.
Called by DoCollect1, when lResize = .T. and lGrid = .T.
Binds the Resize() event of each column of every grid to MyResize() method
- DoCollectG Public
Recursive procedure to get and store fontsize, position and dimension of form's objects (grid's components are not changed).
Called by DoCollect1, when lResize = .T. and lGrid = .F.
- DoCollectD Public
Recursive procedure to get and store fontsize, position and dimension of form's objects.
Called by DoCollect1, when lResize = .T. and lGrid = .T.
- DoResize1 Public
- If lResize = .T. calculate the new values for fontsize, position and dimension of the form, based upon the values from MyCol collection
Depending on the value of the lGrid property, calls DoResize(), respectivelly DoResizeG()
- If lResize = .F. clear the Anchor property of every object
Call DoStopResizing() and unbind the Resize() event of the form to DoResize1() method
- DoResize Public
Recursive procedure to calculate the new values for fontsize, position and dimension of form's objects, based upon the values from MyCol collection
Called by DoResize1, when lResize = .T. and lGrid = .T.
- DoResizeG Public
Recursive procedure to calculate the new values for fontsize, position and dimension of form's objects, based upon the values from MyCol collection (grid's components are not changed)
Called by DoResize1, when lResize = .T. and lGrid = .T.
- DoResize2 Public
- If lResize = .T. calculate the new values for fontsize, position and dimension of the form, based upon the values from MyCol collection
Depending on the value of the lGrid property, calls DoResize(), respectivelly DoResizeG()
- If lResize = .F. clear the Anchor property of every object
Call DoStopResizing() and unbind the Resize() event of the form to DoResize1() method
* Unlike DoResize1, the width and height are resized proportionalli (the same factor of scalling for noth dimensions)
Called from myMagnifier object
- DoResize3 Public
- restore form's objects using values from the myDefa collection
Call DoResized()
- DoResizeD Public
Recursive procedure to restore form's objects using values from the myDefa collection
Called from DoResize3()
- DoStopResizing Public
Recursive method used to clear the Anchor property of form's objects
Called from DoColect1, DoResize1,DoResize2 and lResize_assign
2. MyMagnifier is a ComboBox-based classDrop an instance on your form and add in the form's init() event a line like:
This.MyMagnifier1.oMyResize = This.MyResize1
Properties:- oMyResize Pointer
Public
Pointer to the form's Myresize object
Methods
- InterActiveChange Call DoResize2() method from the MyResize object, based on the value selected from the list
- Valid Call DoResize2() method from the MyResize object, based on the value typed
See
Resizer 2.0
The archive contains:
- res.prg the two classes (prg style)
- demo.prg demo prg (for prg style)
- res.vcx the two classes (class lybrary)
- res.scx demo form
- res.prg demo project
Related posts
http://praisachion.blogspot.com/2016/05/resizer-class-v20.html
http://praisachion.blogspot.com/2016/05/how-to-create-resizer-class-and-zooming.html
New behaviour
- stop resizing objects by changing one property (lresize)
- restore the form in it's original state
- do not resize grid's component objects (columns a.s.o) by changing one property (lgrid)
1. MyResize is a custom-based class
Just drop an instance to your form.
The class will bind it's DoResize1() method to the form's Resize event, and the Resize() event of each column of every grid to myresize()
Object members:
- myCol
Collection
Public
Contains fontsize for each object, columns width for every grid, rowheight and headerheight for every grid. Used as a basis to calculte the corresponding new values of the same properties
- myDefa
Collection
Public
Contains fontsize, position and dimension for each object, rowheight and headerheight for every grid. Used to restore the form in its initial state
Properties:
- lgrid
Logical
Public
.T. (default) the grid's columns width, row and header height and fontsize will be also changed (scaled accordingly)
.F. only the grid's height and width will be changed
- lResize
Logical
Public
.T. when the form changes its dimensions, the objects are scaled
.F.only the form changes dimensions, objects remains untouched
- lScan Logical
Public
.F. (default) the form's object wasn't yet scanned. They will be processed at the first changing in form's dimensions, and lScan will become .T.
.T. the form's object's were processed
When lgrid = .T. and the user manually change the width of some grid's column, then lScan become .F.
- lScanD
Logical
Public
.F. (default) the form's object wasn't yet scanned. They will be processed at the first changing in form's dimensions, and lScanD will become .T.
.T. the form's object's were processed
used to store the initial state of the form (dimensions, positions and fontsize of every object)
- nAmount
Numeric
Public
1 (= 100% default) the scale factor for width
- nAmountH
Numeric
Public
1 (= 100% default) the scale factor for height
Methods:
- Init
Bind the Resize() event of the form to DoResize1() method
- lResize_assign
Public
- If lResize, bind the Resize() event of the form to DoResize1() method, otherwise unbinde them
- If Not lResize and lScan, call DoStopResizing()
- myresize
Public
- set lScan = .F.
- binded to each grid column's Resize() event (when lgrid = .T.)
- DoCollect1 Public
- If Not lScand and MyDefa collection is empty Collects the current fontsize, position and dimension of form's objects and store them to MyDefa collection
Call DoCollectD()
- If lResize = .T. Collects the current fontsize, position and dimension of form's objects and store them to MyCol collection
Depending on the value of the lGrid property, calls DoCollect(), respectivelly DoCollectG()
- If lResize = .F. clear the Anchor property of every object
Call DoStopResizing()
- DoCollect Public
Recursive procedure to get and store fontsize, position and dimension of form's objects.
Called by DoCollect1, when lResize = .T. and lGrid = .T.
Binds the Resize() event of each column of every grid to MyResize() method
- DoCollectG Public
Recursive procedure to get and store fontsize, position and dimension of form's objects (grid's components are not changed).
Called by DoCollect1, when lResize = .T. and lGrid = .F.
- DoCollectD Public
Recursive procedure to get and store fontsize, position and dimension of form's objects.
Called by DoCollect1, when lResize = .T. and lGrid = .T.
- DoResize1 Public
- If lResize = .T. calculate the new values for fontsize, position and dimension of the form, based upon the values from MyCol collection
Depending on the value of the lGrid property, calls DoResize(), respectivelly DoResizeG()
- If lResize = .F. clear the Anchor property of every object
Call DoStopResizing() and unbind the Resize() event of the form to DoResize1() method
- DoResize Public
Recursive procedure to calculate the new values for fontsize, position and dimension of form's objects, based upon the values from MyCol collection
Called by DoResize1, when lResize = .T. and lGrid = .T.
- DoResizeG Public
Recursive procedure to calculate the new values for fontsize, position and dimension of form's objects, based upon the values from MyCol collection (grid's components are not changed)
Called by DoResize1, when lResize = .T. and lGrid = .T.
- DoResize2 Public
- If lResize = .T. calculate the new values for fontsize, position and dimension of the form, based upon the values from MyCol collection
Depending on the value of the lGrid property, calls DoResize(), respectivelly DoResizeG()
- If lResize = .F. clear the Anchor property of every object
Call DoStopResizing() and unbind the Resize() event of the form to DoResize1() method
* Unlike DoResize1, the width and height are resized proportionalli (the same factor of scalling for noth dimensions)
Called from myMagnifier object
- DoResize3 Public
- restore form's objects using values from the myDefa collection
Call DoResized()
- DoResizeD Public
Recursive procedure to restore form's objects using values from the myDefa collection
Called from DoResize3()
- DoStopResizing Public
Recursive method used to clear the Anchor property of form's objects
Called from DoColect1, DoResize1,DoResize2 and lResize_assign
2. MyMagnifier is a ComboBox-based classDrop an instance on your form and add in the form's init() event a line like:
This.MyMagnifier1.oMyResize = This.MyResize1
Properties:- oMyResize Pointer
Public
Pointer to the form's Myresize object
Methods
- InterActiveChange Call DoResize2() method from the MyResize object, based on the value selected from the list
- Valid Call DoResize2() method from the MyResize object, based on the value typed
See
Resizer 2.0
The archive contains:
- res.prg the two classes (prg style)
- demo.prg demo prg (for prg style)
- res.vcx the two classes (class lybrary)
- res.scx demo form
- res.prg demo project
Related posts
http://praisachion.blogspot.com/2016/05/resizer-class-v20.html
http://praisachion.blogspot.com/2016/05/how-to-create-resizer-class-and-zooming.html
joi, 12 mai 2016
How to create a resizer class and a zooming combo
1) The Resizer class
VFP9 come with the Anchor property.
A Resizer class must scan all form's objects and set the Anchor property to 16+32+64+128, for each one.
Because some objects, like grid columns or pages inside a pageframe, does not have the anchor property, or the controls property, require a special attention.
But the class isn't complicated.
At some starting point, a method must collect the original values for FontSize and, in some cases, other properties like RowHeight, HeaderHeight (for a grid) and even Width or Height (for the form itself). These values must be stored somewhere, because they would be used as basis to calculate the new values of the same properties.
Then, in the Resize() event of the form, must be called another method that scans and calculate the new values for each object.
*************************************************************
* The resizer class
*************************************************************
DEFINE CLASS MyResize as Custom
nAmount = 1 && the amount for width
nAmountH = 1 && the amount for height
ADD OBJECT myCol as Collection && stores original width, height or fontsize
* First collect the original sizes and fontsizes
* Collect data for the form
PROCEDURE DoCollect1
This.MyCol.Add(ThisForm.Width,"_orig_Width" + SYS(1272,ThisForm))
This.MyCol.Add(ThisForm.Height,"_orig_Height" + SYS(1272,ThisForm))
This.DoCollect(ThisForm)
ENDPROC
* Collect data for embeded objects
PROCEDURE DoCollect
LPARAMETERS toParent
IF m.toParent = this
RETURN
ENDIF
IF PEMSTATUS(m.toParent,'Anchor',5)
toParent.Anchor = 16+32+64+128
ENDIF
IF PEMSTATUS(m.toParent,'FontSize',5)
This.MyCol.Add(m.toParent.FontSize,"_orig_FontSize" + SYS(1272,toParent))
ENDIF
IF PEMSTATUS(m.toParent,'RowHeight',5) && for grid
This.MyCol.Add(m.toParent.RowHeight,"_orig_RowHeight" + SYS(1272,toParent))
ENDIF
IF PEMSTATUS(m.toParent,'HeaderHeight',5) && for grid
This.MyCol.Add(m.toParent.HeaderHeight,"_orig_HeaderHeight" + SYS(1272,toParent))
ENDIF
IF PEMSTATUS(m.toParent,'Controls',5)
FOR EACH loObj IN m.toParent.Controls
This.DoCollect(m.loObj)
NEXT
ENDIF
IF PEMSTATUS(m.toParent,'Pages',5) && for pageframe
FOR EACH loObj IN m.toParent.Pages
This.DoCollect(m.loObj)
NEXT
ENDIF
IF PEMSTATUS(m.toParent,'Columns',5) && for grid
FOR EACH loObj IN m.toParent.Columns
IF This.MyCol.GetKey("_orig_Width" + SYS(1272,toParent)) = 0
This.MyCol.Add(m.loObj.Width,"_orig_Width" + SYS(1272,toParent))
ENDIF
This.DoCollect(m.loObj)
NEXT
ENDIF
ENDPROC
* The resize method (change form's appearance)
PROCEDURE DoResize1
This.nAmount = ThisForm.Width / This.MyCol.Item("_orig_Width" + SYS(1272,ThisForm))
This.nAmountH = ThisForm.Height / This.MyCol.Item("_orig_Height" + SYS(1272,ThisForm))
This.DoResize(ThisForm)
TRY
ThisForm.FontSize = CEILING(This.MyCol.Item("_orig_FontSize" + SYS(1272,ThisForm)) * MIN(This.nAmount, This.nAmountH))
CATCH
ENDTRY
ENDPROC
* The magnifying method (change form's appearance)
PROCEDURE DoResize2
LPARAMETERS tnAmount
IF m.tnAmount > 0
STORE m.tnAmount TO This.nAmount, This.nAmountH
ThisForm.Width = m.tnAmount * This.MyCol.Item("_orig_Width" + SYS(1272,ThisForm))
ThisForm.Height = m.tnAmount * This.MyCol.Item("_orig_Height" + SYS(1272,ThisForm))
This.DoResize(ThisForm)
ENDIF
TRY
ThisForm.FontSize = CEILING(This.MyCol.Item("_orig_FontSize" + SYS(1272,ThisForm)) * MIN(This.nAmount, This.nAmountH))
CATCH
ENDTRY
ENDPROC
* The resize method (adjust form's objects)
PROCEDURE DoResize
LPARAMETERS toParent
LOCAL loObj
IF PEMSTATUS(m.toParent,'FontSize',5)
TRY
toParent.FontSize = FLOOR(This.MyCol.Item("_orig_FontSize" + SYS(1272,toParent)) * MIN(This.nAmount, This.nAmountH))
CATCH
ENDTRY
ENDIF
IF PEMSTATUS(m.toParent,'RowHeight',5) && for grid
toParent.RowHeight = CEILING(This.MyCol.Item("_orig_RowHeight" + SYS(1272,toParent)) * This.nAmountH)
ENDIF
IF PEMSTATUS(m.toParent,'HeaderHeight',5) && for grid
toParent.HeaderHeight = CEILING(This.MyCol.Item("_orig_HeaderHeight" + SYS(1272,toParent)) * This.nAmountH)
ENDIF
IF PEMSTATUS(m.toParent,'Controls',5)
FOR EACH loObj IN m.toParent.Controls
This.DoResize(m.loObj)
NEXT
ENDIF
IF PEMSTATUS(m.toParent,'Pages',5) && for pageframe
FOR EACH loObj IN m.toParent.Pages
This.DoResize(m.loObj)
NEXT
ENDIF
IF PEMSTATUS(m.toParent,'Columns',5) && for grid
FOR EACH loObj IN m.toParent.Columns
loObj.Width = CEILING(This.MyCol.Item("_orig_Width" + SYS(1272,toParent)) * This.nAmount)
This.DoResize(m.loObj)
NEXT
ENDIF
ENDPROC
ENDDEFINE
*************************************************************
* End of the resizer class
*************************************************************
2) The Zooming tool
Having this class, it's easy to build a combobox that provide the "zoom" facility
In the Interactivechange() and Valid() event of that class, simply must be called the appropriate method form the Resizer class.
***************************
* The magnifier combo
***************************
DEFINE CLASS MyMagnifier as ComboBox
oMyResize = Null && pointer to the Resizer object
RowSourceType = 1
RowSource = "25%,50%,75%,100%,125%,150%,200%"
Value = "100%"
Format = "KT"
PROCEDURE Interactivechange
IF TYPE("This.oMyResize") = "O" AND !ISNULL(This.oMyResize)
This.oMyResize.DoResize2(VAL(This.Value)/100)
ENDIF
This.SelStart = LEN(ALLTRIM(This.DisplayValue))
ENDPROC
PROCEDURE Valid
IF TYPE("This.oMyResize") = "O" AND !ISNULL(This.oMyResize)
This.oMyResize.DoResize2(VAL(This.DisplayValue)/100)
ENDIF
ENDPROC
ENDDEF
*******************************
* End of the magnifier combo
*******************************
3) Example
Here is a complete example, with a form that uses those two classes
As you can see, the Init() method of the form call the DoCollect1() method of the Resizer class, while the Resize() method of the form call the DoResize1() method of the Resizer class
PUBLIC ofrm
ofrm = CREATEOBJECT("MyForm")
ofrm.show()
DEFINE CLASS MyForm as Form
width = 500
height = 300
ADD OBJECT txt as textbox WITH top = 30
ADD OBJECT cmd as commandbutton WITH top = 30,left = 100
ADD OBJECT grd as grid WITH top = 70, RecordSource = 'cc'
ADD OBJECT pgf as PageFrame WITH left = 350,width = 150,height = 250,Pagecount = 2
ADD OBJECT Resizer as MyResize
ADD OBJECT Magnifier as MyMagnifier &&WITH oMyResize = ThisForm.Resizer
PROCEDURE Load
CREATE CURSOR cc (ii I DEFAULT RECNO()+6,cc C(10) DEFAULT SYS(2015))
FOR lni = 1 TO 10
APPEND BLANK
NEXT
GO TOP IN 'cc'
ENDPROC
PROCEDURE Init
This.pgf.Page1.AddObject("txt","textbox")
This.pgf.Page1.AddObject("cmd","commandbutton")
This.pgf.Page1.cmd.top = 40
This.pgf.Page1.AddObject("grd","grid")
This.pgf.Page1.grd.top = 80
This.pgf.Page1.grd.RecordSource = 'cc'
This.pgf.Page1.SetAll("Visible",.T.)
This.pgf.Page2.AddObject("pgf","pageframe")
This.pgf.Page2.pgf.Pagecount = 1
This.pgf.Page2.pgf.width = 100
This.pgf.Page2.pgf.height = 200
This.pgf.Page2.pgf.Page1.AddObject("txt","textbox")
This.pgf.Page2.pgf.Page1.AddObject("cmd","commandbutton")
This.pgf.Page2.pgf.Page1.cmd.top = 40
This.pgf.Page2.pgf.Visible = .T.
This.pgf.Page2.pgf.Page1.SetAll("Visible",.T.)
* Set the oMyResize property of the Magnifier combobox
This.Magnifier.oMyResize = ThisForm.Resizer
* Initialize the Resizer object (collect the original dimension of the form's objects)
This.Resizer.DoCollect1
ENDPROC
* When you resize the form, the objects are scaled
PROCEDURE Resize
This.Resizer.DoResize1
ENDPROC
ENDDEFINE
***************************
* The magnifier combo
***************************
DEFINE CLASS MyMagnifier as ComboBox
oMyResize = Null && pointer to the Resizer object
RowSourceType = 1
RowSource = "25%,50%,75%,100%,125%,150%,200%"
Value = "100%"
Format = "KT"
PROCEDURE Interactivechange
IF TYPE("This.oMyResize") = "O" AND !ISNULL(This.oMyResize)
This.oMyResize.DoResize2(VAL(This.Value)/100)
ENDIF
This.SelStart = LEN(ALLTRIM(This.DisplayValue))
ENDPROC
PROCEDURE Valid
IF TYPE("This.oMyResize") = "O" AND !ISNULL(This.oMyResize)
This.oMyResize.DoResize2(VAL(This.DisplayValue)/100)
ENDIF
ENDPROC
ENDDEF
*******************************
* End of the magnifier combo
*******************************
*************************************************************
* The resizer class
*************************************************************
DEFINE CLASS MyResize as Custom
nAmount = 1 && the amount for width
nAmountH = 1 && the amount for height
ADD OBJECT myCol as Collection && stores original width, height or fontsize
* First collect the original sizes and fontsizes
* Collect data for the form
PROCEDURE DoCollect1
This.MyCol.Add(ThisForm.Width,"_orig_Width" + SYS(1272,ThisForm))
This.MyCol.Add(ThisForm.Height,"_orig_Height" + SYS(1272,ThisForm))
This.DoCollect(ThisForm)
ENDPROC
* Collect data for embeded objects
PROCEDURE DoCollect
LPARAMETERS toParent
IF m.toParent = this
RETURN
ENDIF
IF PEMSTATUS(m.toParent,'Anchor',5)
toParent.Anchor = 16+32+64+128
ENDIF
IF PEMSTATUS(m.toParent,'FontSize',5)
This.MyCol.Add(m.toParent.FontSize,"_orig_FontSize" + SYS(1272,toParent))
ENDIF
IF PEMSTATUS(m.toParent,'RowHeight',5) && for grid
This.MyCol.Add(m.toParent.RowHeight,"_orig_RowHeight" + SYS(1272,toParent))
ENDIF
IF PEMSTATUS(m.toParent,'HeaderHeight',5) && for grid
This.MyCol.Add(m.toParent.HeaderHeight,"_orig_HeaderHeight" + SYS(1272,toParent))
ENDIF
IF PEMSTATUS(m.toParent,'Controls',5)
FOR EACH loObj IN m.toParent.Controls
This.DoCollect(m.loObj)
NEXT
ENDIF
IF PEMSTATUS(m.toParent,'Pages',5) && for pageframe
FOR EACH loObj IN m.toParent.Pages
This.DoCollect(m.loObj)
NEXT
ENDIF
IF PEMSTATUS(m.toParent,'Columns',5) && for grid
FOR EACH loObj IN m.toParent.Columns
IF This.MyCol.GetKey("_orig_Width" + SYS(1272,toParent)) = 0
This.MyCol.Add(m.loObj.Width,"_orig_Width" + SYS(1272,toParent))
ENDIF
This.DoCollect(m.loObj)
NEXT
ENDIF
ENDPROC
* The resize method (change form's appearance)
PROCEDURE DoResize1
This.nAmount = ThisForm.Width / This.MyCol.Item("_orig_Width" + SYS(1272,ThisForm))
This.nAmountH = ThisForm.Height / This.MyCol.Item("_orig_Height" + SYS(1272,ThisForm))
This.DoResize(ThisForm)
TRY
ThisForm.FontSize = CEILING(This.MyCol.Item("_orig_FontSize" + SYS(1272,ThisForm)) * MIN(This.nAmount, This.nAmountH))
CATCH
ENDTRY
ENDPROC
* The magnifying method (change form's appearance)
PROCEDURE DoResize2
LPARAMETERS tnAmount
IF m.tnAmount > 0
STORE m.tnAmount TO This.nAmount, This.nAmountH
ThisForm.Width = m.tnAmount * This.MyCol.Item("_orig_Width" + SYS(1272,ThisForm))
ThisForm.Height = m.tnAmount * This.MyCol.Item("_orig_Height" + SYS(1272,ThisForm))
This.DoResize(ThisForm)
ENDIF
TRY
ThisForm.FontSize = CEILING(This.MyCol.Item("_orig_FontSize" + SYS(1272,ThisForm)) * MIN(This.nAmount, This.nAmountH))
CATCH
ENDTRY
ENDPROC
* The resize method (adjust form's objects)
PROCEDURE DoResize
LPARAMETERS toParent
LOCAL loObj
IF PEMSTATUS(m.toParent,'FontSize',5)
TRY
toParent.FontSize = FLOOR(This.MyCol.Item("_orig_FontSize" + SYS(1272,toParent)) * MIN(This.nAmount, This.nAmountH))
CATCH
ENDTRY
ENDIF
IF PEMSTATUS(m.toParent,'RowHeight',5) && for grid
toParent.RowHeight = CEILING(This.MyCol.Item("_orig_RowHeight" + SYS(1272,toParent)) * This.nAmountH)
ENDIF
IF PEMSTATUS(m.toParent,'HeaderHeight',5) && for grid
toParent.HeaderHeight = CEILING(This.MyCol.Item("_orig_HeaderHeight" + SYS(1272,toParent)) * This.nAmountH)
ENDIF
IF PEMSTATUS(m.toParent,'Controls',5)
FOR EACH loObj IN m.toParent.Controls
This.DoResize(m.loObj)
NEXT
ENDIF
IF PEMSTATUS(m.toParent,'Pages',5) && for pageframe
FOR EACH loObj IN m.toParent.Pages
This.DoResize(m.loObj)
NEXT
ENDIF
IF PEMSTATUS(m.toParent,'Columns',5) && for grid
FOR EACH loObj IN m.toParent.Columns
loObj.Width = CEILING(This.MyCol.Item("_orig_Width" + SYS(1272,toParent)) * This.nAmount)
This.DoResize(m.loObj)
NEXT
ENDIF
ENDPROC
ENDDEFINE
*************************************************************
* End of the resizer class
*************************************************************
See also
https://www.foxite.com/archives/enlarging-a-form-0000436495.htm
Related posts
http://praisachion.blogspot.com/2016/05/resizer-class-v20.html
http://praisachion.blogspot.com/2016/05/how-to-create-resizer-class-and-zooming.html
VFP9 come with the Anchor property.
A Resizer class must scan all form's objects and set the Anchor property to 16+32+64+128, for each one.
Because some objects, like grid columns or pages inside a pageframe, does not have the anchor property, or the controls property, require a special attention.
But the class isn't complicated.
At some starting point, a method must collect the original values for FontSize and, in some cases, other properties like RowHeight, HeaderHeight (for a grid) and even Width or Height (for the form itself). These values must be stored somewhere, because they would be used as basis to calculate the new values of the same properties.
Then, in the Resize() event of the form, must be called another method that scans and calculate the new values for each object.
*************************************************************
* The resizer class
*************************************************************
DEFINE CLASS MyResize as Custom
nAmount = 1 && the amount for width
nAmountH = 1 && the amount for height
ADD OBJECT myCol as Collection && stores original width, height or fontsize
* First collect the original sizes and fontsizes
* Collect data for the form
PROCEDURE DoCollect1
This.MyCol.Add(ThisForm.Width,"_orig_Width" + SYS(1272,ThisForm))
This.MyCol.Add(ThisForm.Height,"_orig_Height" + SYS(1272,ThisForm))
This.DoCollect(ThisForm)
ENDPROC
* Collect data for embeded objects
PROCEDURE DoCollect
LPARAMETERS toParent
IF m.toParent = this
RETURN
ENDIF
IF PEMSTATUS(m.toParent,'Anchor',5)
toParent.Anchor = 16+32+64+128
ENDIF
IF PEMSTATUS(m.toParent,'FontSize',5)
This.MyCol.Add(m.toParent.FontSize,"_orig_FontSize" + SYS(1272,toParent))
ENDIF
IF PEMSTATUS(m.toParent,'RowHeight',5) && for grid
This.MyCol.Add(m.toParent.RowHeight,"_orig_RowHeight" + SYS(1272,toParent))
ENDIF
IF PEMSTATUS(m.toParent,'HeaderHeight',5) && for grid
This.MyCol.Add(m.toParent.HeaderHeight,"_orig_HeaderHeight" + SYS(1272,toParent))
ENDIF
IF PEMSTATUS(m.toParent,'Controls',5)
FOR EACH loObj IN m.toParent.Controls
This.DoCollect(m.loObj)
NEXT
ENDIF
IF PEMSTATUS(m.toParent,'Pages',5) && for pageframe
FOR EACH loObj IN m.toParent.Pages
This.DoCollect(m.loObj)
NEXT
ENDIF
IF PEMSTATUS(m.toParent,'Columns',5) && for grid
FOR EACH loObj IN m.toParent.Columns
IF This.MyCol.GetKey("_orig_Width" + SYS(1272,toParent)) = 0
This.MyCol.Add(m.loObj.Width,"_orig_Width" + SYS(1272,toParent))
ENDIF
This.DoCollect(m.loObj)
NEXT
ENDIF
ENDPROC
* The resize method (change form's appearance)
PROCEDURE DoResize1
This.nAmount = ThisForm.Width / This.MyCol.Item("_orig_Width" + SYS(1272,ThisForm))
This.nAmountH = ThisForm.Height / This.MyCol.Item("_orig_Height" + SYS(1272,ThisForm))
This.DoResize(ThisForm)
TRY
ThisForm.FontSize = CEILING(This.MyCol.Item("_orig_FontSize" + SYS(1272,ThisForm)) * MIN(This.nAmount, This.nAmountH))
CATCH
ENDTRY
ENDPROC
* The magnifying method (change form's appearance)
PROCEDURE DoResize2
LPARAMETERS tnAmount
IF m.tnAmount > 0
STORE m.tnAmount TO This.nAmount, This.nAmountH
ThisForm.Width = m.tnAmount * This.MyCol.Item("_orig_Width" + SYS(1272,ThisForm))
ThisForm.Height = m.tnAmount * This.MyCol.Item("_orig_Height" + SYS(1272,ThisForm))
This.DoResize(ThisForm)
ENDIF
TRY
ThisForm.FontSize = CEILING(This.MyCol.Item("_orig_FontSize" + SYS(1272,ThisForm)) * MIN(This.nAmount, This.nAmountH))
CATCH
ENDTRY
ENDPROC
* The resize method (adjust form's objects)
PROCEDURE DoResize
LPARAMETERS toParent
LOCAL loObj
IF PEMSTATUS(m.toParent,'FontSize',5)
TRY
toParent.FontSize = FLOOR(This.MyCol.Item("_orig_FontSize" + SYS(1272,toParent)) * MIN(This.nAmount, This.nAmountH))
CATCH
ENDTRY
ENDIF
IF PEMSTATUS(m.toParent,'RowHeight',5) && for grid
toParent.RowHeight = CEILING(This.MyCol.Item("_orig_RowHeight" + SYS(1272,toParent)) * This.nAmountH)
ENDIF
IF PEMSTATUS(m.toParent,'HeaderHeight',5) && for grid
toParent.HeaderHeight = CEILING(This.MyCol.Item("_orig_HeaderHeight" + SYS(1272,toParent)) * This.nAmountH)
ENDIF
IF PEMSTATUS(m.toParent,'Controls',5)
FOR EACH loObj IN m.toParent.Controls
This.DoResize(m.loObj)
NEXT
ENDIF
IF PEMSTATUS(m.toParent,'Pages',5) && for pageframe
FOR EACH loObj IN m.toParent.Pages
This.DoResize(m.loObj)
NEXT
ENDIF
IF PEMSTATUS(m.toParent,'Columns',5) && for grid
FOR EACH loObj IN m.toParent.Columns
loObj.Width = CEILING(This.MyCol.Item("_orig_Width" + SYS(1272,toParent)) * This.nAmount)
This.DoResize(m.loObj)
NEXT
ENDIF
ENDPROC
ENDDEFINE
*************************************************************
* End of the resizer class
*************************************************************
2) The Zooming tool
Having this class, it's easy to build a combobox that provide the "zoom" facility
In the Interactivechange() and Valid() event of that class, simply must be called the appropriate method form the Resizer class.
***************************
* The magnifier combo
***************************
DEFINE CLASS MyMagnifier as ComboBox
oMyResize = Null && pointer to the Resizer object
RowSourceType = 1
RowSource = "25%,50%,75%,100%,125%,150%,200%"
Value = "100%"
Format = "KT"
PROCEDURE Interactivechange
IF TYPE("This.oMyResize") = "O" AND !ISNULL(This.oMyResize)
This.oMyResize.DoResize2(VAL(This.Value)/100)
ENDIF
This.SelStart = LEN(ALLTRIM(This.DisplayValue))
ENDPROC
PROCEDURE Valid
IF TYPE("This.oMyResize") = "O" AND !ISNULL(This.oMyResize)
This.oMyResize.DoResize2(VAL(This.DisplayValue)/100)
ENDIF
ENDPROC
ENDDEF
*******************************
* End of the magnifier combo
*******************************
3) Example
Here is a complete example, with a form that uses those two classes
As you can see, the Init() method of the form call the DoCollect1() method of the Resizer class, while the Resize() method of the form call the DoResize1() method of the Resizer class
PUBLIC ofrm
ofrm = CREATEOBJECT("MyForm")
ofrm.show()
DEFINE CLASS MyForm as Form
width = 500
height = 300
ADD OBJECT txt as textbox WITH top = 30
ADD OBJECT cmd as commandbutton WITH top = 30,left = 100
ADD OBJECT grd as grid WITH top = 70, RecordSource = 'cc'
ADD OBJECT pgf as PageFrame WITH left = 350,width = 150,height = 250,Pagecount = 2
ADD OBJECT Resizer as MyResize
ADD OBJECT Magnifier as MyMagnifier &&WITH oMyResize = ThisForm.Resizer
PROCEDURE Load
CREATE CURSOR cc (ii I DEFAULT RECNO()+6,cc C(10) DEFAULT SYS(2015))
FOR lni = 1 TO 10
APPEND BLANK
NEXT
GO TOP IN 'cc'
ENDPROC
PROCEDURE Init
This.pgf.Page1.AddObject("txt","textbox")
This.pgf.Page1.AddObject("cmd","commandbutton")
This.pgf.Page1.cmd.top = 40
This.pgf.Page1.AddObject("grd","grid")
This.pgf.Page1.grd.top = 80
This.pgf.Page1.grd.RecordSource = 'cc'
This.pgf.Page1.SetAll("Visible",.T.)
This.pgf.Page2.AddObject("pgf","pageframe")
This.pgf.Page2.pgf.Pagecount = 1
This.pgf.Page2.pgf.width = 100
This.pgf.Page2.pgf.height = 200
This.pgf.Page2.pgf.Page1.AddObject("txt","textbox")
This.pgf.Page2.pgf.Page1.AddObject("cmd","commandbutton")
This.pgf.Page2.pgf.Page1.cmd.top = 40
This.pgf.Page2.pgf.Visible = .T.
This.pgf.Page2.pgf.Page1.SetAll("Visible",.T.)
* Set the oMyResize property of the Magnifier combobox
This.Magnifier.oMyResize = ThisForm.Resizer
* Initialize the Resizer object (collect the original dimension of the form's objects)
This.Resizer.DoCollect1
ENDPROC
* When you resize the form, the objects are scaled
PROCEDURE Resize
This.Resizer.DoResize1
ENDPROC
ENDDEFINE
***************************
* The magnifier combo
***************************
DEFINE CLASS MyMagnifier as ComboBox
oMyResize = Null && pointer to the Resizer object
RowSourceType = 1
RowSource = "25%,50%,75%,100%,125%,150%,200%"
Value = "100%"
Format = "KT"
PROCEDURE Interactivechange
IF TYPE("This.oMyResize") = "O" AND !ISNULL(This.oMyResize)
This.oMyResize.DoResize2(VAL(This.Value)/100)
ENDIF
This.SelStart = LEN(ALLTRIM(This.DisplayValue))
ENDPROC
PROCEDURE Valid
IF TYPE("This.oMyResize") = "O" AND !ISNULL(This.oMyResize)
This.oMyResize.DoResize2(VAL(This.DisplayValue)/100)
ENDIF
ENDPROC
ENDDEF
*******************************
* End of the magnifier combo
*******************************
*************************************************************
* The resizer class
*************************************************************
DEFINE CLASS MyResize as Custom
nAmount = 1 && the amount for width
nAmountH = 1 && the amount for height
ADD OBJECT myCol as Collection && stores original width, height or fontsize
* First collect the original sizes and fontsizes
* Collect data for the form
PROCEDURE DoCollect1
This.MyCol.Add(ThisForm.Width,"_orig_Width" + SYS(1272,ThisForm))
This.MyCol.Add(ThisForm.Height,"_orig_Height" + SYS(1272,ThisForm))
This.DoCollect(ThisForm)
ENDPROC
* Collect data for embeded objects
PROCEDURE DoCollect
LPARAMETERS toParent
IF m.toParent = this
RETURN
ENDIF
IF PEMSTATUS(m.toParent,'Anchor',5)
toParent.Anchor = 16+32+64+128
ENDIF
IF PEMSTATUS(m.toParent,'FontSize',5)
This.MyCol.Add(m.toParent.FontSize,"_orig_FontSize" + SYS(1272,toParent))
ENDIF
IF PEMSTATUS(m.toParent,'RowHeight',5) && for grid
This.MyCol.Add(m.toParent.RowHeight,"_orig_RowHeight" + SYS(1272,toParent))
ENDIF
IF PEMSTATUS(m.toParent,'HeaderHeight',5) && for grid
This.MyCol.Add(m.toParent.HeaderHeight,"_orig_HeaderHeight" + SYS(1272,toParent))
ENDIF
IF PEMSTATUS(m.toParent,'Controls',5)
FOR EACH loObj IN m.toParent.Controls
This.DoCollect(m.loObj)
NEXT
ENDIF
IF PEMSTATUS(m.toParent,'Pages',5) && for pageframe
FOR EACH loObj IN m.toParent.Pages
This.DoCollect(m.loObj)
NEXT
ENDIF
IF PEMSTATUS(m.toParent,'Columns',5) && for grid
FOR EACH loObj IN m.toParent.Columns
IF This.MyCol.GetKey("_orig_Width" + SYS(1272,toParent)) = 0
This.MyCol.Add(m.loObj.Width,"_orig_Width" + SYS(1272,toParent))
ENDIF
This.DoCollect(m.loObj)
NEXT
ENDIF
ENDPROC
* The resize method (change form's appearance)
PROCEDURE DoResize1
This.nAmount = ThisForm.Width / This.MyCol.Item("_orig_Width" + SYS(1272,ThisForm))
This.nAmountH = ThisForm.Height / This.MyCol.Item("_orig_Height" + SYS(1272,ThisForm))
This.DoResize(ThisForm)
TRY
ThisForm.FontSize = CEILING(This.MyCol.Item("_orig_FontSize" + SYS(1272,ThisForm)) * MIN(This.nAmount, This.nAmountH))
CATCH
ENDTRY
ENDPROC
* The magnifying method (change form's appearance)
PROCEDURE DoResize2
LPARAMETERS tnAmount
IF m.tnAmount > 0
STORE m.tnAmount TO This.nAmount, This.nAmountH
ThisForm.Width = m.tnAmount * This.MyCol.Item("_orig_Width" + SYS(1272,ThisForm))
ThisForm.Height = m.tnAmount * This.MyCol.Item("_orig_Height" + SYS(1272,ThisForm))
This.DoResize(ThisForm)
ENDIF
TRY
ThisForm.FontSize = CEILING(This.MyCol.Item("_orig_FontSize" + SYS(1272,ThisForm)) * MIN(This.nAmount, This.nAmountH))
CATCH
ENDTRY
ENDPROC
* The resize method (adjust form's objects)
PROCEDURE DoResize
LPARAMETERS toParent
LOCAL loObj
IF PEMSTATUS(m.toParent,'FontSize',5)
TRY
toParent.FontSize = FLOOR(This.MyCol.Item("_orig_FontSize" + SYS(1272,toParent)) * MIN(This.nAmount, This.nAmountH))
CATCH
ENDTRY
ENDIF
IF PEMSTATUS(m.toParent,'RowHeight',5) && for grid
toParent.RowHeight = CEILING(This.MyCol.Item("_orig_RowHeight" + SYS(1272,toParent)) * This.nAmountH)
ENDIF
IF PEMSTATUS(m.toParent,'HeaderHeight',5) && for grid
toParent.HeaderHeight = CEILING(This.MyCol.Item("_orig_HeaderHeight" + SYS(1272,toParent)) * This.nAmountH)
ENDIF
IF PEMSTATUS(m.toParent,'Controls',5)
FOR EACH loObj IN m.toParent.Controls
This.DoResize(m.loObj)
NEXT
ENDIF
IF PEMSTATUS(m.toParent,'Pages',5) && for pageframe
FOR EACH loObj IN m.toParent.Pages
This.DoResize(m.loObj)
NEXT
ENDIF
IF PEMSTATUS(m.toParent,'Columns',5) && for grid
FOR EACH loObj IN m.toParent.Columns
loObj.Width = CEILING(This.MyCol.Item("_orig_Width" + SYS(1272,toParent)) * This.nAmount)
This.DoResize(m.loObj)
NEXT
ENDIF
ENDPROC
ENDDEFINE
*************************************************************
* End of the resizer class
*************************************************************
See also
https://www.foxite.com/archives/enlarging-a-form-0000436495.htm
Related posts
http://praisachion.blogspot.com/2016/05/resizer-class-v20.html
http://praisachion.blogspot.com/2016/05/how-to-create-resizer-class-and-zooming.html
Abonați-vă la:
Postări (Atom)