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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resizing a form

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
621
GB
I have subclassed several controls, command buttons, text boxes, labels &c. and have subclassed the standard form as amform.

When amform is re-sized at run time it visits all the controls of the form and re-calculates their position, size and fontsize. In general this works fine. In the case of a grid, subclassed as amgrid, this itself has a resize() method. When this is called (as a result of the form re-sizing) this visits each of its columns and adjust its width. This also works OK.

However I have a difficulty with the option group (subclassed as amoption).; when this is re-sized, I would like it to visit each of its option buttons and re-calculate its Top and Width properties; this is based on the current scaling of the form and on the original values of Top and Width for the button, which I would like to save as properties of the option button.

To that end I believe that I need to subclass the option button (as ambutton) and give it these two additional properties. However I do not know how to include these subclassed buttons (ambutton) in my subclassed option group (amoption). When the button count on amoption is altered at design time, it creates extra buttons as class optionbutton, rather than as my subclassed ambutton.

I see that there has been previous discussions on this matter on this site - I am probably attempting something which has been done many times before, or perhaps over-complicating the issue - but would be grateful for guidance.
 
Hi Andrew,

Did you have a look at FOR EACH?
e.g.

FOR EACH loButton IN amoption
IF UPPER(loButton.BASECLASS) = "OPTIONBUTTON"​
code​
ENDIF​
ENDFOR

or even at the ANCHOR property of controls?

hth

MK
 
Thank you MK

In fact I already use the FOR EACH construct to loop through the controls of the form and (separately) to loop through the buttons in the option group. This is the way by which I get the form to visit each control to adjust its position, size and fontsize

The problem I run up against is that I need to have extra properties on the option buttons to remember the original position, width and font size of each button (I have not found a setting of Anchor which handles that).

To do this I have to subclass optionbutton to make my own ambutton. But then I have not found a way to include instances of ambutton as part of the option group - by default all buttons added to an option group seem to be of the base class, optionbutton, not my own sub-classed ambutton.

Andrew

 
See the OptionGrop's MemberClass and MemberClassLibrary properties. Tell it to use whatever option button class you want.
 
Andrew,

To subclass an option button, first create a new class in the usual way, based on the native option button. Save it under a name of your choice, in a library of your choice. (You do all this in the visual class designer).

Then, in your option group class, set the MemberClass property to the name of the above class, and set the MemberClassLibrary to the name of the library where you stored it.

You can then set the option group's ButtonCount to an appropriate number. All the buttons thus created will be based on your option button class.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you very much, Dan and Mike. I believe that has pointed me in the right direction.

My original reason for adopting this approach was that I did not know about the Anchor property - so my own ignorance!

However, after experimenting a little with the Anchor property (which I believe I should - if starting again - apply to each of my own controls) - I am not sure what setting of Anchor I need to apply to each of my base classes (e.g. my own Textbox, Grid, Commandbutton &c) so that they get preserved in shape, relative position, fontsize when their containing form is re-sized.

At present I adopt the following approach if the user (perhaps rather oddly), uses the mouse to double the height of a form and make it 50% wider. I double the .top and .height properties and increase the .left and width by 50%. I increase the fontsize by the lesser of these two increases, so by 50%.

There are some side-effects. Suppose I double the height of a form but leave its width unchanged. All the controls become taller and narrower. Within a grid the fontsize remains unchanged and so does the row height; so the number of visible rows increases.

Andrew

 
Andrew,

If you are not sure what Anchor settings to use, the solution is to use the Anchor Editor: select the Anchor property in the Properties list, then click the three-dots button to the right of the text box at the top of the list. The Anchor Editor is a simple interactive dialogue that will generate the correct setting for you.

Now, that said, I have to ask exactly why you want to resize an option group? In general, you would resize a form to give more room for the user to view or edit the text in a text box, edit box, grid, combo box, or similar control. But resizing an option group is like resizing a command button. It doesn't allow the user to see any more (or less) information. The information that is visible remains the same: you are simply showing it in a different size space. You simply get bigger (or smaller) buttons.

If that's what you want, that's fine. But are you sure it's what you are trying to achieve?

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
The anchor editor's options for option groups offer pretty much what Mike is suggesting.

I've yet to use a form (as a user myself) that resizes in a way that's actually useful, so I tend not to include the behavior.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top