Mega Code Archive

 
Categories / Delphi / Forms
 

Another Way to Limits or Restrict MinMax Size of a Form

Title: Another Way to Limits or Restrict Min/Max Size of a Form Question: How to limit/restrict the resizeable size of a form in order to avoid "damaged"/unwanted Form appearance Answer: in Delphi 7 there is a form's event "OnConstrainedResize" that we can use to solve this kinda problem The steps are: 1. We must set the min size of our form @onCreateForm event 2. We can also set the max size of our form @onCreateForm event 3. Write code to the "OnConstrainedResize" event of the Form == procedure [FormConstrainedResize] Here is the code I mentioned : ============================== unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure FormConstrainedResize(Sender: TObject; var MinWidth, MinHeight, MaxWidth, MaxHeight: Integer); private { Private declarations } FMinWidth, FMinHeight, FMaxWidth, FMaxHeight : Integer; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin FMinHeight := Self.Height; FMinWidth := Self.Width; FMaxWidth := Self.Width + 100; FMaxHeight := Self.Height + 100; end; procedure TForm1.FormConstrainedResize(Sender: TObject; var MinWidth, MinHeight, MaxWidth, MaxHeight: Integer); begin MinWidth := FMinWidth; MinHeight := FMinHeight; MaxWidth := FMaxWidth; MaxHeight := FMaxHeight; end; end. ============================== // end of the code ps: previous article about relative same topic is founded in article_874 (by Hosni SaqAllah)