Line class

A Line is a windowless lightweight control that draws a single straight line segment from one point to another on its container. It exists purely for visual presentation — to divide regions of a form, underline a heading, draw a leader to an annotation — and has no interaction surface of its own: no mouse events, no focus, no caption.

A Line is positioned by its two endpoints, X1 / Y1 and X2 / Y2, rather than by a Left / Top / Width / Height rectangle. The default property is Visible and the default event is Initialize.

Private Sub Form_Load()
    linUnderHeading.X1 = 120 :  linUnderHeading.Y1 = 320
    linUnderHeading.X2 = 4800 : linUnderHeading.Y2 = 320
    linUnderHeading.BorderColor = vbBlue
    linUnderHeading.BorderWidth = 2
End Sub

Endpoints

X1 / Y1 is one endpoint of the line; X2 / Y2 is the other. Coordinates are in the container’s ScaleMode units (twips by default) and are measured from the top-left corner of the container’s client area. The line is drawn between the two points regardless of which is “earlier” — swapping the endpoints does not change the result.

The control has no Width or Height of its own; the bounding rectangle is derived from the two endpoints. Resizing a Line at design time moves whichever endpoint is being dragged.

Pen

The line is drawn with a Win32 GDI pen whose appearance is controlled by:

  • BorderColor — the colour of the pen (defaults to the system window-text colour).
  • BorderWidth — the pen width in pixels (default 1).
  • BorderStyle — the pen pattern, as a member of BorderStyleConstants: vbTransparent (0), vbBSSolid (1, default), vbBSDash (2), vbBSDot (3), vbBSDashDot (4), vbBSDashDotDot (5), or vbBSInsideSolid (6).

GDI applies a hard limitation here: when BorderWidth is greater than 1, the OS forces a solid pen even if BorderStyle requests a dashed or dotted pattern. Use width 1 if the pattern matters.

Draw mode

DrawMode selects the raster operation that combines the pen with the destination pixels. A member of DrawModeConstants: vbCopyPen (default — opaque drawing) or one of the XOR / AND / NOT / merge variants. Non-default modes are mainly useful for “rubber-band” feedback drawn over an existing background — the same XOR you draw twice cancels itself out, restoring the original pixels.

No interaction surface

Unlike most other controls, a Line does not raise mouse, keyboard, or focus events of any kind, and has no Caption, Enabled, or ToolTipText. To make a region clickable, place a transparent Label on top.

Properties

BorderColor

The colour of the line, as an OLE_COLOR. Defaults to the system window-text colour.

BorderStyle

The pen pattern. A member of BorderStyleConstants: vbTransparent (0), vbBSSolid (1, default), vbBSDash (2), vbBSDot (3), vbBSDashDot (4), vbBSDashDotDot (5), or vbBSInsideSolid (6). Forced to vbBSSolid by Win32 whenever BorderWidth is greater than 1.

BorderWidth

The pen width, in pixels. Long, default 1. Widths greater than 1 ignore BorderStyle and always draw solid.

Container

The control that hosts this line — typically the form, a Frame, or a UserControl. Read with Get, change with Set.

ControlType

A read-only ControlTypeConstants value identifying this control. The Line shares the vbShape constant with the Shape control — both are windowless, points-based geometric primitives with no dedicated control-type identifier.

DrawMode

The raster operation that the line drawing applies when combining the pen with the destination. A member of DrawModeConstants: vbCopyPen (default) is normal opaque drawing; other values produce XOR, AND, NOT, and other pixel-mixing effects.

Index

When the line is part of a control array, the Long zero-based index of this instance within the array. Reading Index on a non-array instance raises run-time error 343 (Object not an array). Read-only at run time.

Name

The unique design-time name of the control on its parent. Read-only at run time.

Parent

A reference to the Form (or UserControl) that ultimately contains the line. Read-only.

Tag

A free-form String the application can use to associate custom data with the line. Ignored by the framework.

Visible

Whether the line is shown. Boolean, default True. Default property.

X1

The horizontal position of the first endpoint, in the container’s ScaleMode units. Double.

X2

The horizontal position of the second endpoint, in the container’s ScaleMode units. Double.

Y1

The vertical position of the first endpoint, in the container’s ScaleMode units. Double.

Y2

The vertical position of the second endpoint, in the container’s ScaleMode units. Double.

Methods

ZOrder

Brings the line to the front or back of the windowless-sibling stack within its container.

Syntax: object.ZOrder [ Position ]

Position
optional A member of ZOrderConstants: vbBringToFront (0, default) or vbSendToBack (1).

Events

Initialize

Raised once, after the line has been wired into its container’s paint cycle but before it is first painted. Default event.

Syntax: object_Initialize( )