Form Building

One Control, One Pattern

Every GPAL form control -- button, checkbox, input, combo box, grid, chart, and the rest -- is built the same way: a fluent chain of With... Settings, completed with a cast to the control's type (e.g. (Input)) and handed to WithFormControl. Learn the pattern once and every control type follows it.

GPALControl: The Shared Base

Every control type -- button, input, checkbox, combo box, data grid, chart, and the rest -- derives from a shared base that provides the settings common to all of them: the visible label, an identifying name for logs, an enabled state, a tooltip, and an event handler. Each specific control type then adds only what is unique to it -- a checked state for checkboxes, a placeholder for text inputs, chart-specific options for charts. The shared settings are the same fluent calls no matter which control you are building.

// Shared settings (WithText, WithName, WithEnabled) work the same on every control type

var saveButton = GPAL.Button

.WithText("Save")

.WithName("SaveButton")

.WithEnabled(true)

.WithCallback<EventHandler>(SaveButton_Click)

.ForEvent(ControlEventType.Click)

.ToGPALObject();

var agreeCheckbox = GPAL.Checkbox

.WithText("I agree to the terms")

.WithChecked(false)

.ToGPALObject();

Assembling a Form

GPAL.Form starts the form's own chain. WithTitle, WithWidth, WithHeight, WithLeft, and WithTop set up the window itself. Each control's chain is completed with a cast to its concrete type, such as (Input) or (Button). The preferred, more readable shorthand. And passed straight to WithFormControl, which can be called repeatedly to add controls one at a time. The form doesn't need to know what's inside each control. It just arranges whatever object it's handed.

var form = GPAL.Form

.WithTitle("Customer Entry")

.WithWidth(600)

.WithHeight(400)

.WithFormControl((Input)GPAL.Input

.WithText("Customer Name"))

.WithFormControl((Input)GPAL.Input

.WithText("Email Address"))

.WithFormControl((Button)GPAL.Button

.WithText("Submit"))

.ToGPALObject();

Picking the Right Control

GPAL ships controls for every common form need: free text entry in single-line or multi-line variants, yes/no and one-of-many choices, list pickers, structured data grids, tree views, constrained inputs for dates, numbers, and file paths, progress and status indicators, and layout panels for organizing controls into pages or grids. Each control type has its own Library Reference page with its specific settings.