Skip to main content

Problem:

Release: 5.0 .NET / Visual Studio 2005

How to change the Height and Width of a Form at runtime?

In a .Net WinForms application there is a possibility to override the defined form size in the Form_loading event that is triggered when a Form is loaded.

Resolution:

An example is attached that shows how to do this. The project is Visual Studio 2005/Net Express 5 based.

In the code there is the need to create an instance of System.Drawing.Size class and pass this to the Form using code such as:-

        repository.

           interface S-ComponentModel-IContainer as "System.ComponentModel.IContainer"

           class System-Windows-Forms-Form as "System.Windows.Forms.Form"

           class System-ComponentModel-Container as "System.ComponentModel.Container"

           class System-Drawing-Size as "System.Drawing.Size"

           Class System-EventHandler as "System.EventHandler"

           Class System-EventArgs as "System.EventArgs"

           class cSize as "System.Drawing.Size"

       .

..........

       method-id.  "FormSize_Form1_Load" final private.

       linkage section.

       01 sender object.

       01 e System-EventArgs.

       procedure division using by value  sender e.

       

           set self::"Size" to new cSize(1000,1000)

       

       end method "FormSize_Form1_Load".

Attachments:

FormSize.zip

Old KB# 4390