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

Override form size at program start

Status
Not open for further replies.

bobbie100

Programmer
Aug 29, 2003
64
GB
I have an existing program developed using the IDE with the size of the main form set by values of ClientWidth & ClientHeight in the Object Inspector. I now find I need to set the size of the main form at start up derived from data read from a file during form create.

However, deriving the values of ClientWidth & ClientHeight in CreateForm seem to get overridden by the values set in the .dfm file.

Is there any way I can stop the .dfm values being used or override these values after they are loaded, but before the form is first displayed?
 
I'm not absolutely certain, but you may be able to use the "OnShow" event handler to do this.

-Dell
 
I save Top, Left, Width, and Height of every screen on formclose, and restore it next time the screen is built in formcreate so the users get the screens right back where they were when closed. I never have to change the ClientWidth and ClientHeight. The forms resize immediately on setting those values and exiting formcreate.

JGS
 
Many thanks to hilfy and jgs for responding. In trying out your suggestions I found the problem was not as I had stated.

The reason for setting the form size is to match the size of a descendant of TGraphicControl which is being used as the display surface. The problem was that after setting ClientHeight and ClientWidth to match the size of the control the form was actually being sized slightly wider and left a strip of the form showing along the right edge.

In fact the window was being resized, but the effect was due to an interaction with the scroll bars. I allowed for scrolling in the program so that the user could reduce the size of the window and still have access to the whole of the control surface.

In the test case that highlighted the problem, the drawing surface was taller than the ClientHeight set at design time. As a result, when the ClientWidth was set first the form was resized with a scroll bar present on the right edge of the form. When the ClientHeight was then resized, the scrollbar was no longer needed and a strip of the form surface was left on the right hand side.

I have fixed this issue, by disabling the scrolling at design time and then turning it on after the ClientHeight & ClientWidth have been set.
 
Further update.
I have now discovered the AutoSize property! It does just what I want at startup.
I set AutoSize to True at design-time and set it False at the first pass through Paint. (OnPaint:=Paint)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top