LoadForm Command, Load Event

Action:

LoadForm loads a Form designed in the Form Editor, which initiates a Load event.

Syntax

LoadForm frm [options] [, x, y]

frm:Form object
options:
[Center | Client3D | Full | Default | Hidden | Tool | Help | Top | Palette | Fixed | NoCaption | NoTitle]
x, y:iexp

Sub Form_Load [(Index%)]

Description

LoadForm name loads a Form which was designed earlier in the GFA-BASIC 32 Form editor. The name must be the name given in properties window. Eventually, the Load event sub is invoked.

At design time the initial layout of the form can be determined using the Form's StartUpMode and Visible properties. However not all the attributes of a window can be set at design time. To overcome this limitation a number of flags can be specified in the LoadForm command. These flags allow you to initially center the window or create full screen window.

At design time you can set the Owned property determining that the form is to be loaded as an owned window. When set and when executing LoadForm, the form will be owned by the current active window (Me). When Me = Nothing at the time of execution of LoadForm the Owned property is ignored.

The Owned property permits you to specify that the form being shown is to be owned by the current active form. When you use this option, you achieve two interesting effects: the owned form is always shown in front of its owner (parent), even if the parent has the focus, and when the parent form is closed or minimized, all forms it owns are also automatically closed or minimized. You can take advantage of this feature to create floating forms that host a toolbar, a palette of tools, a group of icons, and so on. This technique is most effective if combined with the window state options Fixed and/or Tool/Palette.

Options Meaning
Center centers the form, overrules StartUpMode property
Full creates a maximized window, overrules StartUpMode, excludes Hidden (full windows are always visible).
Default default, overrules StartUpMode
Hidden invisible, overrules Visible property
Client3D set WS_EX_CLIENTEDGE, overrules Appearance
Tool creates a WS_EX_TOOLWINDOW
Help includes a Help button in the window caption
Top creates a top window
Palette creates a WS_EX_PALETTEWINDOW
Fixed a non-sizable window
NoCaption no title bar
NoTitle no title bar, alias

Using any of the additional parameters ignore the design time property Visible.

When the optional x and y are specified, the design time properties Left and Top are ignored.

The LoadForm command generates a Load event, which is not invoked immediately! The event sub is called when the form is made visible, which is not before a DoEvents or Sleep handles the events. The Load event sub can be used to perform initialization tasks like creating a menu, toolbar, and statusbar.

To load a MdiChild form, you must make sure to activate its owner/parent, the window/form with its property MdiParent set to True. Since LoadForm sets Me, and child windows are loaded after the parent window is created, this would hardly cause any problem.

Example

// To run this example you must first create a Form...

// ... using the Form Editor and name that form frm1

LoadForm frm1

Do

Sleep

Loop Until Me Is Nothing

 

Sub frm1_Load

' Initialization code

Global Dim mnu$()

Array mnu$() = "&File"#10 "&New"#10 "&Open"#10 "&Save"#10 _

"Save &As"#10 "-"#10 "E&xit"#10 #10 _

"&Edit"#10 "&Undo"#10 "-"#10 "Copy"#10 "Cut"#10 "Paste"#10 #10 _

"&Help"#10 "&About"#10 #10

Menu mnu$()

EndSub

Remarks

To create a form in code use the Form statement or the GFA-BASIC 16 commands OpenW, ChildW, ParentW, and Dialog, they create forms as well. However, these commands do not generate a Load event, though.

Known Issues

  1. If Client3D is listed as an option, an IDE interpreter error is raised. There is currently no known workaround for this error.
    [Reported by Roger Cabo, 03/08/2022]
  2. The Top option does not seem to work. Instead, once you have loaded the form, used the OnTop method to set this attribute as follows:

    LoadForm frm

    frm.OnTop = True

    [Reported by Roger Cabo, 09/08/2022]
  3. See Also

    Form Object, Form, OpenW, ChildW, ParentW, Dialog, SaveFormPos, LoadFormPos, ModifyStyle, ModifyExStyle, WinDpi, ScaleToDpi, ScaleXYWHToDpi, WM_DPICHANGED.

    {Created by Sjouke Hamstra; Last updated: 11/08/2022 by James Gaite; Other Contributors: Jean-Marie Melanson}