# FormExtensions

Namespace: **Wisej.Web.Markup**

Assembly: **Wisej.Framework** (4.0.0.0)

Adds [fluent markup](https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/markup/markup) extension methods to the [Form](/api/wisej.web/containers/form.md) class.

{% tabs %}
{% tab title="C#" %}

```csharp
public class FormExtensions
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Class FormExtensions
```

{% endtab %}
{% endtabs %}

## Methods

### ![](/files/lIX317sDtMTZJBi9oSIx) AcceptButton\<TForm>(form, acceptButton)

Sets the accept button for the specified [Form](/api/wisej.web/containers/form.md) control, which is clicked when the user presses the Enter key.

| Parameter        | Type                                                                         | Description                                                                              |
| ---------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **TForm**        |                                                                              | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md). |
| **form**         | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md) | The form for which to set the accept button.                                             |
| **acceptButton** | [Button](/api/wisej.web/buttons/button.md)                                   | The button to be set as the accept button.                                               |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The form with the updated accept button.

This method allows you to specify a button that will be activated when the Enter key is pressed, providing a convenient way to submit forms.

```csharp

myForm.AcceptButton(mySubmitButton);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) AutoSize\<TForm>(form, autoSize, mode)

Sets the AutoSize property and AutoSizeMode for the specified [Form](/api/wisej.web/containers/form.md) control, enabling or disabling automatic resizing.

| Parameter    | Type                                                                         | Description                                                                              |
| ------------ | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **TForm**    |                                                                              | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md). |
| **form**     | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md) | The form for which to set the AutoSize property and mode.                                |
| **autoSize** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)              | A boolean value indicating whether to enable automatic resizing. Default is `false`.     |
| **mode**     | [AutoSizeMode](/api/wisej.web/enumerations/wisej.web.autosizemode.md)        | The auto size mode to be applied if autoSize is enabled.                                 |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The form with the updated AutoSize property and mode.

This method allows you to control the automatic resizing behavior of the form based on its contents.

```csharp

myForm.AutoSize(true, AutoSizeMode.GrowAndShrink);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) CancelButton\<TForm>(form, cancelButton)

Sets the cancel button for the specified [Form](/api/wisej.web/containers/form.md) control, which is clicked when the user presses the Esc key.

| Parameter        | Type                                                                         | Description                                                                              |
| ---------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **TForm**        |                                                                              | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md). |
| **form**         | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md) | The form for which to set the cancel button.                                             |
| **cancelButton** | [Button](/api/wisej.web/buttons/button.md)                                   | The button to be set as the cancel button.                                               |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The form with the updated cancel button.

This method allows you to specify a button that will be activated when the Esc key is pressed, providing a convenient way to cancel operations.

```csharp

myForm.CancelButton(myCancelButton);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) Icon\<TForm>(form, icon)

Sets the icon for the specified [Form](/api/wisej.web/containers/form.md) control.

| Parameter | Type                                                                         | Description                                                                              |
| --------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **TForm** |                                                                              | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md). |
| **form**  | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md) | The form for which to set the icon.                                                      |
| **icon**  | [Image](https://docs.microsoft.com/dotnet/api/system.drawing.image)          | The image to be used as the form's icon.                                                 |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The form with the updated icon.

This method allows you to specify an image to be displayed as the form's icon in the title bar and taskbar.

```csharp

myForm.Icon(myIconImage);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) Icon\<TForm>(form, iconSource)

Sets the icon for the specified [Form](/api/wisej.web/containers/form.md) control using the provided icon source.

| Parameter      | Type                                                                         | Description                                                                              |
| -------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **TForm**      |                                                                              | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md). |
| **form**       | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md) | The form for which to set the icon.                                                      |
| **iconSource** | [String](https://docs.microsoft.com/dotnet/api/system.string)                | The source of the icon to be applied to the form.                                        |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The form with the updated icon.

This method allows you to specify an icon for the form by providing a source path or identifier for the icon.

```csharp

myForm.Icon("path/to/icon.png");

```

### ![](/files/lIX317sDtMTZJBi9oSIx) IconLarge\<TForm>(form, icon)

Sets the large icon for the specified [Form](/api/wisej.web/containers/form.md) control.

| Parameter | Type                                                                         | Description                                                                              |
| --------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **TForm** |                                                                              | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md). |
| **form**  | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md) | The form for which to set the icon.                                                      |
| **icon**  | [Image](https://docs.microsoft.com/dotnet/api/system.drawing.image)          | The image to be used as the form's icon.                                                 |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The form with the updated icon.

This method allows you to specify an image to be displayed as the form's icon in the title bar and taskbar.

```csharp

myForm.Icon(myIconImage);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) IconLarge\<TForm>(form, iconSource)

Sets the large icon for the specified [Form](/api/wisej.web/containers/form.md) control using the provided icon source.

| Parameter      | Type                                                                         | Description                                                                              |
| -------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **TForm**      |                                                                              | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md). |
| **form**       | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md) | The form for which to set the large icon.                                                |
| **iconSource** | [String](https://docs.microsoft.com/dotnet/api/system.string)                | The source of the large icon to be applied to the form.                                  |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The form with the updated large icon.

This method allows you to specify a large icon for the form by providing a source path or identifier for the icon.

```csharp

myForm.IconLarge("path/to/largeIcon.ico");

```

### ![](/files/lIX317sDtMTZJBi9oSIx) IsMdiContainer\<TForm>(form, value)

Sets the [IsMdiContainer](/api/wisej.web/containers/form.md#ismdicontainer) property of the form.

| Parameter | Type                                                                         | Description                                                                              |
| --------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **TForm** |                                                                              | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md). |
| **form**  | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md) | The form instance on which to set the property.                                          |
| **value** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)              | A boolean value indicating whether the form is an MDI container.                         |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The form instance with the updated property.

This method allows you to fluently set the [IsMdiContainer](/api/wisej.web/containers/form.md#ismdicontainer) property.

```csharp

var form = new Form().IsMdiContainer(true);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) KeepCentered\<TForm>(form, value)

Sets whether the specified form should remain centered on the screen.

| Parameter | Type                                                                         | Description                                                                              |
| --------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **TForm** |                                                                              | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md). |
| **form**  | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md) | The form instance to configure.                                                          |
| **value** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)              | `true` to keep the form centered; `false` otherwise.                                     |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The same form instance, allowing for method chaining.

This extension method configures the form to remain centered on the screen. When enabled, the form will automatically reposition itself to the center of the display.

### ![](/files/lIX317sDtMTZJBi9oSIx) KeepOnScreen\<TForm>(form, value)

Sets whether the specified form should remain visible within the screen boundaries.

| Parameter | Type                                                                         | Description                                                                              |
| --------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **TForm** |                                                                              | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md). |
| **form**  | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md) | The form instance to configure.                                                          |
| **value** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)              | `true` to keep the form on screen; `false` otherwise.                                    |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The same form instance, allowing for method chaining.

This extension method configures the form to remain within the visible area of the screen, preventing it from being moved outside the display boundaries.

### ![](/files/lIX317sDtMTZJBi9oSIx) MdiParent\<TForm>(form, value)

Sets the [MdiParent](/api/wisej.web/containers/form.md#mdiparent) property of the form.

| Parameter | Type                                                                         | Description                                                                              |
| --------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **TForm** |                                                                              | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md). |
| **form**  | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md) | The form instance on which to set the property.                                          |
| **value** | [Form](/api/wisej.web/containers/form.md)                                    | The parent form to be set as the MDI parent.                                             |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The form instance with the updated property.

This method allows you to fluently set the [MdiParent](/api/wisej.web/containers/form.md#mdiparent) property.

### ![](/files/lIX317sDtMTZJBi9oSIx) OnActivated\<TForm>(form, action)

Attaches an action to the Activated event of a form.

| Parameter  | Type                                                                         | Description                                                                              |
| ---------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **TForm**  |                                                                              | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md). |
| **form**   | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md) | The form to attach the event handler to.                                                 |
| **action** | [Action\<TForm>](https://docs.microsoft.com/dotnet/api/system.action-1)      | The action to execute when the form is activated.                                        |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The form with the attached Activated event handler.

This method allows you to execute a specific action when the form's Activated event is triggered.

```csharp

myForm.OnActivated(f => f.Text = "Form Activated");

```

### ![](/files/lIX317sDtMTZJBi9oSIx) OnClosed\<TForm>(form, action)

Attaches an action to the Closed event of a form.

| Parameter  | Type                                                                         | Description                                                                              |
| ---------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **TForm**  |                                                                              | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md). |
| **form**   | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md) | The form to attach the event handler to.                                                 |
| **action** | [Action\<TForm>](https://docs.microsoft.com/dotnet/api/system.action-1)      | The action to execute when the form is closed.                                           |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The form with the attached Closed event handler.

This method allows you to execute a specific action when the form's Closed event is triggered.

```csharp

myForm.OnClosed(f => MessageBox.Show("Form Closed"));

```

### ![](/files/lIX317sDtMTZJBi9oSIx) OnClosing\<TForm>(form, action)

Attaches an action to the Closing event of a form.

| Parameter  | Type                                                                                     | Description                                                                                                                                                                                          |
| ---------- | ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **TForm**  |                                                                                          | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md).                                                                                                             |
| **form**   | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md)             | The form to attach the event handler to.                                                                                                                                                             |
| **action** | [Action\<TForm, CancelEventArgs>](https://docs.microsoft.com/dotnet/api/system.action-2) | The action to execute when the form is closing. The [CancelEventArgs](https://docs.microsoft.com/dotnet/api/system.componentmodel.canceleventargs) parameter allows you to cancel the closing event. |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The form with the attached Closing event handler.

This method allows you to execute a specific action when the form's Closing event is triggered, and optionally cancel the closing.

```csharp

myForm.OnClosing((f, args) => {
if (!ConfirmClose())
args.Cancel = true;
});

```

### ![](/files/lIX317sDtMTZJBi9oSIx) OnDeactivate\<TForm>(form, action)

Attaches an action to the Deactivate event of a form.

| Parameter  | Type                                                                         | Description                                                                              |
| ---------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **TForm**  |                                                                              | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md). |
| **form**   | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md) | The form to attach the event handler to.                                                 |
| **action** | [Action\<TForm>](https://docs.microsoft.com/dotnet/api/system.action-1)      | The action to execute when the form is deactivated.                                      |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The form with the attached Deactivate event handler.

This method allows you to execute a specific action when the form's Deactivate event is triggered.

```csharp

myForm.OnDeactivate(f => f.Text = "Form Deactivated");

```

### ![](/files/lIX317sDtMTZJBi9oSIx) OnLoad\<TForm>(form, action)

Attaches an action to the Load event of a form.

| Parameter  | Type                                                                         | Description                                                                              |
| ---------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **TForm**  |                                                                              | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md). |
| **form**   | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md) | The form to attach the event handler to.                                                 |
| **action** | [Action\<TForm>](https://docs.microsoft.com/dotnet/api/system.action-1)      | The action to execute when the form is loaded.                                           |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The form with the attached Load event handler.

This method allows you to execute a specific action when the form's Load event is triggered.

```csharp

myForm.OnLoad(f => f.Text = "Form Loaded");

```

### ![](/files/lIX317sDtMTZJBi9oSIx) OnMdiChildActivate\<TForm>(form, action)

Subscribes an action to the [MdiChildActivate](/api/wisej.web/containers/form.md#mdichildactivate) event of the form.

| Parameter  | Type                                                                         | Description                                                                              |
| ---------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **TForm**  |                                                                              | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md). |
| **form**   | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md) | The form instance on which to subscribe the event.                                       |
| **action** | [Action\<TForm>](https://docs.microsoft.com/dotnet/api/system.action-1)      | The action to be executed when the MDI child is activated.                               |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The form instance with the event subscription.

This method allows you to fluently subscribe to the [MdiChildActivate](/api/wisej.web/containers/form.md#mdichildactivate) event.

```csharp

var form = new Form().OnMdiChildActivate(childForm => AlertBox.Show("MDI Child Activated"));

```

### ![](/files/lIX317sDtMTZJBi9oSIx) ShowInTaskbar\<TForm>(form, value)

Sets the [ShowInTaskbar](/api/wisej.web/containers/form.md#showintaskbar) property of the form.

| Parameter | Type                                                                         | Description                                                                              |
| --------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **TForm** |                                                                              | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md). |
| **form**  | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md) | The form instance on which to set the property.                                          |
| **value** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)              | A boolean value indicating whether the form is shown in the Windows taskbar.             |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The form instance with the updated property.

This method allows you to fluently set the [ShowInTaskbar](/api/wisej.web/containers/form.md#showintaskbar) property.

### ![](/files/lIX317sDtMTZJBi9oSIx) ShowModalMask\<TForm>(form, value)

Sets the `ShowModalMask` property of the form.

| Parameter | Type                                                                         | Description                                                                              |
| --------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **TForm** |                                                                              | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md). |
| **form**  | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md) | The form instance on which to set the property.                                          |
| **value** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)              | A boolean value indicating whether to show a modal mask.                                 |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The form instance with the updated property.

This method allows you to fluently set the `ShowModalMask` property.

### ![](/files/lIX317sDtMTZJBi9oSIx) StartPosition\<TForm>(form, startPosition)

Sets the start position for the specified [Form](/api/wisej.web/containers/form.md) control, determining the initial position of the form when it is displayed.

| Parameter         | Type                                                                               | Description                                                                                                                                            |
| ----------------- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **TForm**         |                                                                                    | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md).                                                               |
| **form**          | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md)       | The form for which to set the start position.                                                                                                          |
| **startPosition** | [FormStartPosition](/api/wisej.web/containers/form/wisej.web.formstartposition.md) | The start position to be applied to the form, specified as a [FormStartPosition](/api/wisej.web/containers/form/wisej.web.formstartposition.md) value. |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The form with the updated start position.

This method allows you to control where the form appears on the screen when it is first shown.

```csharp

myForm.StartPosition(FormStartPosition.CenterScreen);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) TopLevel\<TForm>(form, value)

Sets the [TopLevel](/api/wisej.web/containers/form.md#toplevel) property of the form.

| Parameter | Type                                                                         | Description                                                                              |
| --------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **TForm** |                                                                              | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md). |
| **form**  | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md) | The form instance on which to set the property.                                          |
| **value** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)              | A boolean value indicating whether the form is a top-level window.                       |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The form instance with the updated property.

This method allows you to fluently set the [TopLevel](/api/wisej.web/containers/form.md#toplevel) property.

### ![](/files/lIX317sDtMTZJBi9oSIx) WindowState\<TForm>(form, windowState)

Sets the window state for the specified [Form](/api/wisej.web/containers/form.md) control.

| Parameter       | Type                                                                           | Description                                                                                                                                      |
| --------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| **TForm**       |                                                                                | The type of the form, which must inherit from [Form](/api/wisej.web/containers/form.md).                                                         |
| **form**        | [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md)   | The form for which to set the window state.                                                                                                      |
| **windowState** | [FormWindowState](/api/wisej.web/containers/form/wisej.web.formwindowstate.md) | The window state to be applied to the form, specified as a [FormWindowState](/api/wisej.web/containers/form/wisej.web.formwindowstate.md) value. |

**Returns:** [TForm](/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md). The form with the updated window state.

This method allows you to control the state of the form's window, such as minimized, maximized, or normal.

```csharp

myForm.WindowState(FormWindowState.Maximized);

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/api/wisej.web.markup/extensions/wisej.web.markup.formextensions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
