Form

Form Layout and Controls

WithTitle sets the text that appears in the form's title bar. WithIcon sets the icon in the title bar and on the taskbar. It takes an .ico as it is, or a .png, .jpg or .bmp that it makes into one, and a file that is not there is reported as a WARNING while the form keeps the icon it has. Without WithIcon a form shows the program's own icon when its project sets ApplicationIcon, and the GPAL robot head when it does not, never the Windows default. WithWidth and WithHeight set the initial window size in pixels, and a form given no WithHeight takes the height its content needs, and WithLeft and WithTop its initial position on the screen.

WithFormControl adds a control, a GPALButton, GPALChart, GPALInput and so on, to the form. Every call adds one more, in the order they appear, and that order is the order they are laid out. GPAL.SpacerFor(pixels) puts a gap of exactly that height between two of them. The form and its controls are the foundation for interactive GPAL workflows and for the AI ShowForm integration.

WithButtonWidth sets the width every button on the form takes, unless that button asked for its own. 0 leaves buttons stretching the full width of the form, which is what they do without it.

On a control rather than the form, WithWidth and WithHeight set that control's size in pixels. A control given a width keeps it and sits centered instead of stretching. WithTag holds any object alongside a control for the workflow's own use, and WithToolTipDelay sets how long a tooltip stays on screen once it appears, at least a second.

Two controls have no page of their own. GPALSlider takes WithOrientation for horizontal or vertical and WithTickFrequency for how often a tick is drawn. GPALTableLayoutPanel takes WithColumnCount for how many columns it lays out and WithGrowStyle for whether it adds rows or columns as controls arrive.

NOTE

GPAL turns on visual styles and GDI text when the first form is built, so Main needs no Application.EnableVisualStyles or Application.SetCompatibleTextRenderingDefault. GDI text is what draws emoji on buttons instead of empty boxes. A program that already has a form on screen when GPAL builds its first one has made its own choice, and GPAL leaves the text setting as it is.

Examples

GPAL Fluent: High-level fluent C# API

//WithButtonWidth is said once on the form and every button takes it, so a form full of buttons does not need the width repeated on each one. A button that says its own WithWidth keeps that instead, and a form that says neither leaves its buttons stretching the full width. Both are settings read as each control is built, not live properties: say them before the form is shown. WithButtonWidth is the exception, and it can be said again while the form is up to resize every button that did not ask for its own, with 0 putting them back to stretching. WithIcon is only needed when the form should look different from the program. A project that sets ApplicationIcon gets that icon on every form it shows, with no code at all. Controls are laid out in the order they are added. The captions are built inline with LabelFor because nothing reads them back; the inputs and buttons are declared fields because the handlers do.

// each control is its own field, so a handler can reach it by name

static GPALInput customer = (GPALInput)GPAL.Input

.WithPlaceholder("customer name")

.WithName("customer");


static GPALInput email = (GPALInput)GPAL.Input

.WithPlaceholder("you@example.com")

.WithName("email");


static GPALButton submit = (GPALButton)GPAL.Button

.Default

.WithText("Submit")

.WithCallback<EventHandler>(SubmitClicked)

.WithName("submit");


// this one says its own width, which wins over the form's

static GPALButton cancel = (GPALButton)GPAL.Button

.WithText("Cancel")

.WithWidth(90)

.WithCallback<EventHandler>((s, e) => myForm.Hide())

.WithName("cancel");


myForm = GPAL.Form

.WithTitle("Customer Entry")

.WithIcon(@"C:iconscustomers.ico") // or leave it out for the program's own icon

.WithWidth(350)

.WithButtonWidth(175) // both buttons, half the form, centered

.WithHeight(400)

.WithLeft(100)

.WithTop(100)

.WithFormControl(GPAL.LabelFor("Customer:"))

.WithFormControl(customer)

.WithFormControl(GPAL.LabelFor("Email:"))

.WithFormControl(email)

.WithFormControl(submit)

.WithFormControl(cancel)

.ToGPALObject();


myForm.ShowDialog();

💬 Ask GPAL