McBasic™Get McBasic™ ↗
Build 881
Components · Nonvisual component
ContextMenu component icon

ContextMenu

Attach a contextual menu to the intended target control.

5 properties1 events0 methodsDefault: Click

Use it in a Form#

The target relationship determines where the menu appears. Configure it in the component properties rather than drawing a fake menu into the Form. Handle the selected command in the ContextMenu event and leave the target’s normal interaction intact.

Add ContextMenu to the component tray and name it ctxTarget for this example:

PropertyExample value
Target"cmdTarget"
Items"Open\n---\nCopy"
VisibleTrue
EnabledTrue
ClickedIndex-1

A complete handler from Forms/frmMain.bas. The linked lesson includes its surrounding controls, declarations and helpers.

Forms/frmMain.bas
Private Sub ctxTarget_Click()
    lblStatus.Caption = "Context item " & CStr(ctxTarget.ClickedIndex + 1) & " selected."
End Sub

Properties#

Contract defaults are shown below. Where a new control has a different Designer starting value, that value is listed separately.

Target

StringDefault: ""

Name of the visual control that receives this context menu. The target must be declared in the same form.

Items

StringDefault: "Open\nClose"

One context-menu caption per line. A line containing '-' creates a separator; empty lines are ignored.

Visible

BooleanDefault: True

Whether the context menu is available on its target control.

Enabled

BooleanDefault: True

Whether the context menu accepts item interaction.

ClickedIndex

LongDefault: -1

Zero-based index of the last clicked context-menu item; separators do not receive an index and -1 means no item has been clicked.

Range: -1 to 100000.

Events and parameters#

Replace control with the object’s Name when creating a handler. ByRef arguments may be changed by your handler; ByVal arguments report an input value.

Click

Occurs once when the component is logically activated by the user.

Signature — see the complete lesson for an implementation
Private Sub control_Click()

No parameters.

Methods#

No methods are declared in this component’s built-in metadata. Use its documented properties and events; do not infer APIs from a similarly named control in another framework.

Source baseline 20f4bfed6b · Build manifest