Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing parent control properties from child

Status
Not open for further replies.

ron1089

Programmer
Joined
May 21, 2004
Messages
26
Location
US
I need to change the size of the controls of a parent class form from an instance of the parent.

I can change the sizes of all the other pageframes, grids and control on the child form.

How do I change those in the parent?
 
ron1089

Do you mean at design time or run - time? If its design time, modify the parent class, and make the required changes. If it runtime, put the appropriate values in the init of the parent class (or the init of the child).

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
It's at runtime. When I put the changes in the child init, the properties of the parent class do not change. When I place it in the parent class init I get an error message saying that one of the objects cannot be in the container.
 
When I place it in the parent class init I get an error message saying that one of the objects cannot be in the container.

Can you post the code that you are using? Aren't just trying to change the size of a control in the paretn class?

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
In general, the child Init happens before the parent Init. Is it possible that you have code which changes the parent properties after the child Init.?

Jim
 
Hi ron

I am connecting this thread with your previous thread as well.

I assume that you are looking for resizing all the controls in a form. For this, you are collecting all the forms height, width, lft etc properties at the starting from the init of your resize class which has been added on the form just like any other control/class added to the form.

Now the problem is that, this do not find some of the controls added to the form from your classes library.
The reason is that the inits of all the controls first take place.. in the process.. the resize class init also gets fired and then the init of the form adds the pageframe class. I hope you get the point here.... Resize class sees the objects already available and initialises.. then the form adds the pageframe class.

The resolution is to
(1) create a custom event .. for example.. 'myInit' in the resize class. Shift all the init event codes of the resize class to the 'myInit' event code.
(2) add the code in the init of the form.. at the end or suitably after adding all other controls..
This.myResize.myInit()
By this all the controls first get initialized and then the resize class init code is run.

In fact this is a modification, I have done to cmStretcher class (stretchy resize control class) freely available in the net (which I have suggested in some of these tek-tips threads).

:-)

____________________________________________
ramani - (Subramanian.G) :-)
 
*/ THIS CODE IS IN THE INIT EVENT OF THE FORM. IT DOESN'T WORK WITH THE RESIZE() EVENT-ALTHOUGH IT COULD
*/ THE IDEA IS TO CHANGE THE SIZE IF THE SCREEN RESOLUTION OF THE WORK STATION IS NOT 800x600.
*/ set to maximum screen
_screen.windowstate = 2

*/ calc ratio of screen to 800X600 resolution
lnRatioWidth = sysmetric(1)/800
lnRatioHeight = sysmetric(2)/600

*/ set the form dimensions
this.width = int(this.width*lnRatioWidth)
this.height = int(this.height*lnRatioHeight)
this.left = int((.5*lnwidth)-(.5*this.width))
this.top = int((.5*lnheight)-(.5*this.height))
this.fontsize = int(this.fontsize*lnRatioWidth)

********************************************************************************
*/ this works for simple forms without container objects
*/ take each control and change its size and location
lnCtrlCnt = this.controlcount
i = 1
do while i <= lnCtrlCnt
lcCtrlName = "thisform." + thisform.controls(i).name
thisform.controlchangesize(lcCtrlName, lnRatioWidth, lnRatioHeight)
i = i + 1
enddo
********************************************************************************
********************************************************************************



********************************************************************************
*/ THIS IS FOR A COMPLICATED FORM WITH CONTAINERS AND CONTAINERS WITHIN CONTAINERS
*/ CREATE A TEMP FILE WITH BASECLASS,PARENT,OBJNAME FIELD FROM FORMS .SCX FILE.
*/
*/ THIS WORKS AS LONG AS THE FORM CLASS USED HAS NO CONTAINERS. THE CONTAINERS IN
*/ IN THE FORM CLASS DO NOT CHANGE SIZES.
*/
*/ WHEN I TRY TO CHANGE THE SIZE OF CONTROLS IN THE FORM CLASS I GET AN ERROR MESSAGE-
*/ #1744 "OBJECT CLASS IS INVALID FOR THIS CONTAINER"
*/
*/ I DON'T KNOW WHERE TO START WITH THIS.

select 0
use c:\ic\filetemp again
copy stru to c:\ic\tempclass
use c:\ic\tempclass alias ctrlall
append from forms\FORM.scx
replace all CtrlAll.tclass with CtrlAll.class, CtrlAll.tobjname with CtrlAll.objname, ;
CtrlAll.tparent with CtrlAll.parent, CtrlAll.tbaseclass with CtrlAll.baseclass

*/ takes each control on the form and a changes it sizes
lcBaseClassList = "FORM.GRID.OPTIONGROUP.PAGEFRAME.CONTAINER.COMMANDGROUP.PAGE."+;
"LABEL.TEXTBOX.EDITBOX.COMMANDBUTTON.CHECKBOX.COMBOBOX.LISTBOX.SPINNER.SHAPE"
go top
do while .not. eof("ctrlall")
if not upper(allt(ctrlall.baseclass)) $ lcBaseClassList
skip
loop
else
lcTparent = alltrim(ctrlall.tparent)
if upper(substr(lcTparent,1,11)) = "FRMCUSTOMRS"
lcTparent = "thisform" + iif(not empty(alltrim(substr(lcTparent,12))), ;
alltrim(substr(lcTparent,12)),'')
endif
lcCtrlName = lcTparent + iif(not empty(lcTparent) and ;
right(lcTparent,1)<>'.',".","") + alltrim(ctrlall.tobjname)
thisform.controlchangesize(lcCtrlName, lnRatioWidth, lnRatioHeight)
skip
endif
enddo
use
*/
*************************************************************************************



*****************************************************
*/ THIS IS THE METHOD - CONTROLCHANGESIZE
lparameter lcCtrlName , lnRatioWidth, lnRatioHeight

lcWidth = lcCtrlName+".width"
if type("&lcWidth")<>'U'
&lcWidth. = &lcWidth. * lnRatioWidth
endif

ETC FOR HEIGHT, TOP , LEFT, FONT
*****************************************************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top