How to control the OnResize event better?

When user assign a value to ClientHeight or ClientWidth of a form, the dimension of the form is automatically changed, then the OnResize event is triggered.
For example, the statement: Form1.ClientHeight:= 80
can run the code in routine TForm1.FormResize.

I find one case can mess up the running routine of the program, which traps the OnResize event. I want to control the proportion of a form, so I add this line in OnResize event:
[code]
ClientWidth:= Ceil(1.2*ClientHeight);
[/code]
This statement can trigger another resize event. The program also traps OnPaint event, and OnResize event usually triggers OnPaint event. It can run when the program is not so complex, but it is very possible to cause subtle problem in the future if the program becomes more complex.
How can I solve this problem?
Thank you!


Comments

  • : When user assign a value to ClientHeight or ClientWidth of a form, the dimension of the form is automatically changed, then the OnResize event is triggered.
    : For example, the statement: Form1.ClientHeight:= 80
    : can run the code in routine TForm1.FormResize.
    :
    : I find one case can mess up the running routine of the program, which traps the OnResize event. I want to control the proportion of a form, so I add this line in OnResize event:
    : [code]
    : ClientWidth:= Ceil(1.2*ClientHeight);
    : [/code]
    : This statement can trigger another resize event. The program also traps OnPaint event, and OnResize event usually triggers OnPaint event. It can run when the program is not so complex, but it is very possible to cause subtle problem in the future if the program becomes more complex.
    : How can I solve this problem?
    : Thank you!
    :
    :
    :
    Use the Contraints property. This allows you to set the minimum and maximum size of the form, and this is implemented while the user is resizing.
  • Hi! Is it possible that I don't restrict the maximum size of a form, but restrict the ratio of ClientWidth and ClientHeight?
    Thank you!
  • : Hi! Is it possible that I don't restrict the maximum size of a form, but restrict the ratio of ClientWidth and ClientHeight?
    : Thank you!
    :
    Only in the OnResize() event.
  • OK. Thank you!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories