McBasic™Get McBasic™ ↗
Build 881
API reference

Form properties & events

Configure the window deliberately, then preserve the exact signatures of its event handlers.

Form properties#

Select the Form itself in the Designer to edit window settings. Defaults below come from the application contract; a template may save different initial values. Use the access label before assigning a property in BASIC.

Caption

TypeDefaultAccess
String""Designer and BASIC

Window title shown in the title bar. A form saved without Caption shows McBasic™.

Font

TypeDefaultAccess
String""Designer and BASIC

Default font of the form's controls: Family|Size or Family|Size|Regular/Bold|Normal/Italic, size 6–96 DIP. Empty uses the theme font; System uses the theme family.

ForeColor

TypeDefaultAccess
String""Designer and BASIC

Default text color of the form's controls as #RRGGBB. Empty uses the theme color.

BackColor

TypeDefaultAccess
String""Designer and BASIC

Form background color as #RRGGBB. Empty uses the standard light gray #F0F0F0.

Width

TypeDefaultAccess
Double520Designer and BASIC

Width of the form's content area in device-independent points; greater than 0 and within MinWidth to MaxWidth.

Height

TypeDefaultAccess
Double260Designer and BASIC

Height of the form's content area in device-independent points; greater than 0 and within MinHeight to MaxHeight.

MinWidth

TypeDefaultAccess
Double200Designer and BASIC

Smallest width the user can resize the form to, in DIP; greater than 0.

MinHeight

TypeDefaultAccess
Double120Designer and BASIC

Smallest height the user can resize the form to, in DIP; greater than 0.

MaxWidth

TypeDefaultAccess
Double100000Designer and BASIC

Largest width the user can resize the form to, in DIP.

MaxHeight

TypeDefaultAccess
Double100000Designer and BASIC

Largest height the user can resize the form to, in DIP.

MDIForm

TypeDefaultAccess
BooleanFalseDesigner only

Host child Form instances inside this window. A DesktopApp may declare one MDIForm. Cannot be combined with MDIChild. Set in the designer only.

MDIChild

TypeDefaultAccess
BooleanFalseDesigner only

Show instances inside the project's MDIForm instead of as separate windows. Check requires an MDIForm. Set in the designer only.

MDIClientTop

TypeDefaultAccess
Double0Designer only

Top offset in DIP of the MDI child area below the child selector; reserve space for the main Form controls. 0 uses the full workspace. Used only by an MDIForm; set in the designer only.

KeyPreview

TypeDefaultAccess
BooleanFalseDesigner and BASIC

Deliver KeyDown, KeyPress and KeyUp to the Form before the focused control. Setting Handled stops delivery to the control.

StartUpPosition

TypeDefaultAccess
String"CenterOwner"Designer; read-only in BASIC

Where the window first appears. Manual uses Left and Top; CenterScreen centres it on the screen; CenterOwner centres it over the form that shows it (a dialog's owner, or the active window) and on the screen when there is none. An MDI child: Manual uses Left and Top in the MDI area, CenterScreen centres it there, CenterOwner cascades. Read-only in code.

Left

TypeDefaultAccess
Double0Designer and BASIC

Distance in DIP from the left edge of the main screen's visible area to the window frame, used when StartUpPosition is Manual. The designer does not move the form. Setting it in code moves the window; a window is kept with 40 DIP of its title bar on screen. Positions are measured from, and kept on, the main screen, so setting Left or Top in code moves a window on another display back to the main screen.

Top

TypeDefaultAccess
Double0Designer and BASIC

Distance in DIP from the top of the main screen's visible area (below the menu bar) to the window frame, used when StartUpPosition is Manual. The designer does not move the form. Setting it in code moves the window. Positions are measured from, and kept on, the main screen, so setting Left or Top in code moves a window on another display back to the main screen.

BorderStyle

TypeDefaultAccess
String"Sizable"Designer and BASIC

Window frame. Sizable: resizable. Fixed: not resizable, title bar shown; zoom is unavailable. Dialog: not resizable, no minimize or zoom. None: no title bar; ControlBox, MinButton and MaxButton are ignored, and the window closes only from code (Unload Me) or when the app quits (Cmd-Q), so give it its own close button. ToolWindow: on macOS the same as Fixed with close only (no utility panel API). Can be changed in code.

ControlBox

TypeDefaultAccess
BooleanTrueDesigner and BASIC

Enables the close button. False also refuses every other user close; Unload Me, App.Quit and Cmd-Q still close the form, so give it its own close button. Ignored when BorderStyle is None.

MinButton

TypeDefaultAccess
BooleanTrueDesigner and BASIC

Enables the minimize button (to the Dock) for a Sizable or Fixed form.

MaxButton

TypeDefaultAccess
BooleanTrueDesigner and BASIC

Enables the green zoom button for a Sizable form. False greys out only that button: the window keeps macOS full-screen support, and McBasic™ apps have no Enter Full Screen menu item.

WindowState

TypeDefaultAccess
String"Normal"Designer and BASIC

Normal, Minimized (in the Dock) or Maximized (zoomed; full screen also reads Maximized). Maximized needs BorderStyle Sizable and MaxButton; Minimized needs Sizable or Fixed and MinButton. Reflects the user's changes; assignable in code. Use vbNormal, vbMinimized, vbMaximized.

TopMost

TypeDefaultAccess
BooleanFalseDesigner and BASIC

Keeps the window above ordinary windows (floating level). Ignored for an MDI child.

Opacity

TypeDefaultAccess
Double1Designer and BASIC

Window opacity from 0 (transparent) to 1 (opaque). An MDI child applies it to its surface in the MDI area.

Enabled

TypeDefaultAccess
BooleanTrueDesigner and BASIC

Whether the form's controls accept input. False disables every control; the window can still be moved and closed. A BorderStyle None form has no title bar, so while it is disabled only Cmd-Q or code closes it.

Visible

TypeDefaultAccess
BooleanTrueRuntime only

Run time only: assigning True shows a hidden form as Show does, and False hides it (Hide). True on a form that is already shown does nothing; unlike Show, it does not bring the form to the front. The first form of the app is always shown.

Tag

TypeDefaultAccess
String in Designer; Variant in BASIC""Designer and BASIC

Application-defined value; text in the designer (at most 4096 UTF-16 units), any value in code (Variant). McBasic™ does not interpret it.

Cursor

TypeDefaultAccess
String"Default"Designer and BASIC

Pointer shown over the form where no control sets its own: Default, Arrow, Hand, IBeam, Cross, Wait, Help, SizeAll, SizeNS, SizeWE, SizeNWSE, SizeNESW or NotAllowed.

AccessibleName

TypeDefaultAccess
String""Designer and BASIC

Window name announced by assistive technology; empty uses the Caption. At most 256 UTF-16 units.

Picture

TypeDefaultAccess
String""Designer and BASIC

Name of a declared project image resource painted behind the controls, over BackColor. Empty shows only BackColor. Assigning an undeclared or unreadable image in code raises error 481 (Invalid picture). The designer does not draw it.

PictureSizeMode

TypeDefaultAccess
String"Normal"Designer and BASIC

How Picture fills the form: Normal (top-left, natural size), Stretch, Zoom (fit, keep proportions), Center (natural size, centred) or ZoomCrop (fill, keep proportions, crop).

Try window properties without losing the close action#

In a copy of the first-app project, select frmMain. Set Caption to Greeting practice, Width to 640, Height to 360, MinWidth to 480, MinHeight to 260, BorderStyle to Sizable and StartUpPosition to CenterScreen. Keep ControlBox, MinButton and MaxButton enabled. Check and Run, resize the window, then stop it. The following complete Form event can be added for a runtime assignment exercise:

frmMain · complete Form_Load handler
Private Sub Form_Load()
    Me.Caption = "Greeting practice"
    Me.Opacity = 1
    Me.Tag = "practice-window"
End Sub

Keep the existing Click handlers unchanged. Confirm the title, resize limits and close action. Do not assign StartUpPosition in this handler. If experimenting with BorderStyle = None or ControlBox = False, first provide a tested button handler containing Unload Me; those settings change how the user can close the window.

Form events#

The signatures below are contracts, not complete implementations. Add the body for your task and the matching End Sub. Preserve each parameter’s type and ByRef direction.

Initialize#

Occurs once after controls and event bindings are created, before the Form is loaded.

Form event signature
Private Sub Form_Initialize()

No parameters.

Load#

Occurs once after initialization and before the Form is first shown.

Form event signature
Private Sub Form_Load()

No parameters.

Shown#

Occurs after the Form becomes visible; this lifecycle event may use Async Sub.

Form event signature
Private Sub Form_Shown()

No parameters.

Activate#

Occurs when this Form becomes the active ordinary window or active child of its MDI container.

Form event signature
Private Sub Form_Activate()

No parameters.

Deactivate#

Occurs when this Form ceases to be the active ordinary window or active child of its MDI container.

Form event signature
Private Sub Form_Deactivate()

No parameters.

Closing#

Occurs before a close attempt; set Cancel to True to keep the Form open and suppress Closed.

Form event signature
Private Sub Form_Closing(ByRef Cancel As Boolean)
ParameterTypeDirection
CancelBooleanByRef

Closed#

Occurs once after an accepted close, before the Form resources become unavailable.

Form event signature
Private Sub Form_Closed()

No parameters.

Resize#

Occurs after the effective Form client size changes.

Form event signature
Private Sub Form_Resize()

No parameters.

MouseDown#

Occurs when a pointing-device button is pressed on the Form surface outside authored child controls.

Form event signature
Private Sub Form_MouseDown(ByVal Button As MouseButton, ByVal Shift As KeyModifiers, ByVal X As Double, ByVal Y As Double)
ParameterTypeDirection
ButtonMouseButtonByVal
ShiftKeyModifiersByVal
XDoubleByVal
YDoubleByVal

MouseUp#

Occurs when a pointing-device button is released on the Form surface outside authored child controls.

Form event signature
Private Sub Form_MouseUp(ByVal Button As MouseButton, ByVal Shift As KeyModifiers, ByVal X As Double, ByVal Y As Double)
ParameterTypeDirection
ButtonMouseButtonByVal
ShiftKeyModifiersByVal
XDoubleByVal
YDoubleByVal

MouseMove#

Occurs when the pointer moves over the logical McBasic™ control; Button contains the currently held buttons and X/Y are local DIP coordinates.

Form event signature
Private Sub Form_MouseMove(ByVal Button As MouseButtons, ByVal Shift As KeyModifiers, ByVal X As Double, ByVal Y As Double)
ParameterTypeDirection
ButtonMouseButtonsByVal
ShiftKeyModifiersByVal
XDoubleByVal
YDoubleByVal

MouseWheel#

Occurs for normalized pointer-wheel input; Delta is portable, and X/Y are local DIP coordinates.

Form event signature
Private Sub Form_MouseWheel(ByVal Delta As Double, ByVal Shift As KeyModifiers, ByVal X As Double, ByVal Y As Double)
ParameterTypeDirection
DeltaDoubleByVal
ShiftKeyModifiersByVal
XDoubleByVal
YDoubleByVal

DragOver#

Occurs while a control dragged inside the app (DragMode or the Drag method) moves over the Form surface outside other controls: State is 0 when it enters, 2 while it moves over and 1 when it leaves; Source is the dragged control and X, Y are Form client DIP coordinates.

Form event signature
Private Sub Form_DragOver(ByVal Source As Control, ByVal X As Single, ByVal Y As Single, ByVal State As Integer)
ParameterTypeDirection
SourceControlByVal
XSingleByVal
YSingleByVal
StateIntegerByVal

DragDrop#

Occurs when a control dragged inside the app (DragMode or the Drag method) is released over the Form surface outside other controls; Source is the dragged control and X, Y are Form client DIP coordinates.

Form event signature
Private Sub Form_DragDrop(ByVal Source As Control, ByVal X As Single, ByVal Y As Single)
ParameterTypeDirection
SourceControlByVal
XSingleByVal
YSingleByVal

KeyDown#

Occurs before the focused control receives a physical key when KeyPreview is True; set Handled to suppress control delivery.

Form event signature
Private Sub Form_KeyDown(ByVal KeyCode As KeyCode, ByVal Shift As KeyModifiers, ByRef Handled As Boolean)
ParameterTypeDirection
KeyCodeKeyCodeByVal
ShiftKeyModifiersByVal
HandledBooleanByRef

KeyPress#

Occurs for committed Unicode text before the focused control receives it when KeyPreview is True; set Handled to suppress control delivery.

Form event signature
Private Sub Form_KeyPress(ByVal Character As String, ByRef Handled As Boolean)
ParameterTypeDirection
CharacterStringByVal
HandledBooleanByRef

KeyUp#

Occurs before the focused control receives a physical key release when KeyPreview is True; set Handled to suppress control delivery.

Form event signature
Private Sub Form_KeyUp(ByVal KeyCode As KeyCode, ByVal Shift As KeyModifiers, ByRef Handled As Boolean)
ParameterTypeDirection
KeyCodeKeyCodeByVal
ShiftKeyModifiersByVal
HandledBooleanByRef

QueryUnload#

Occurs before closing; set Cancel to a nonzero value to keep the Form open.

Form event signature
Private Sub Form_QueryUnload(ByRef Cancel As Integer, ByVal UnloadMode As Integer)
ParameterTypeDirection
CancelIntegerByRef
UnloadModeIntegerByVal

Unload#

Occurs once after closing is accepted and before Form resources are released.

Form event signature
Private Sub Form_Unload()

No parameters.

Source baseline 20f4bfed6b · Build manifest
Sources & maintenance

Original web explanation, reviewed against these repository sources. API tables and example files follow the implementation.

  • metadata/standard-components.v1.json