Skip to main content
Version: 4.1

FormExtensions

Namespace: Wisej.Web.Markup

Assembly: Wisej.Framework (4.1.0.0)

Adds fluent markup extension methods to the Form class.

public class FormExtensions

Methods

Static member AcceptButton<TForm>(form, acceptButton)

Sets the accept button for the specified Form control, which is clicked when the user presses the Enter key.

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form for which to set the accept button.
acceptButtonButtonThe button to be set as the accept button.

Returns: TForm. 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.


myForm.AcceptButton(mySubmitButton);

Static member AutoSize<TForm>(form, autoSize, mode)

Sets the AutoSize property and AutoSizeMode for the specified Form control, enabling or disabling automatic resizing.

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form for which to set the AutoSize property and mode.
autoSizeBooleanA boolean value indicating whether to enable automatic resizing. Default is false.
modeAutoSizeModeThe auto size mode to be applied if autoSize is enabled.

Returns: TForm. 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.


myForm.AutoSize(true, AutoSizeMode.GrowAndShrink);

Static member CancelButton<TForm>(form, cancelButton)

Sets the cancel button for the specified Form control, which is clicked when the user presses the Esc key.

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form for which to set the cancel button.
cancelButtonButtonThe button to be set as the cancel button.

Returns: TForm. 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.


myForm.CancelButton(myCancelButton);

Static member Icon<TForm>(form, icon)

Sets the icon for the specified Form control.

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form for which to set the icon.
iconImageThe image to be used as the form's icon.

Returns: TForm. 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.


myForm.Icon(myIconImage);

Static member Icon<TForm>(form, iconSource)

Sets the icon for the specified Form control using the provided icon source.

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form for which to set the icon.
iconSourceStringThe source of the icon to be applied to the form.

Returns: TForm. 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.


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

Static member IconLarge<TForm>(form, icon)

Sets the large icon for the specified Form control.

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form for which to set the icon.
iconImageThe image to be used as the form's icon.

Returns: TForm. 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.


myForm.Icon(myIconImage);

Static member IconLarge<TForm>(form, iconSource)

Sets the large icon for the specified Form control using the provided icon source.

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form for which to set the large icon.
iconSourceStringThe source of the large icon to be applied to the form.

Returns: TForm. 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.


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

Static member IsMdiContainer<TForm>(form, value)

Sets the IsMdiContainer property of the form.

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form instance on which to set the property.
valueBooleanA boolean value indicating whether the form is an MDI container.

Returns: TForm. The form instance with the updated property.

This method allows you to fluently set the IsMdiContainer property.


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

Static member KeepCentered<TForm>(form, value)

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

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form instance to configure.
valueBooleantrue to keep the form centered; false otherwise.

Returns: TForm. 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.

Static member KeepOnScreen<TForm>(form, value)

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

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form instance to configure.
valueBooleantrue to keep the form on screen; false otherwise.

Returns: TForm. 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.

Static member MaximizedMargin<TForm>(form, margin)

Sets the margin to be applied when the form is maximized and returns the form instance.

ParameterTypeDescription
TFormThe type of the form, which must derive from Form.
formTFormThe form instance to which the maximized margin will be applied.
marginNullable<Padding>The margin to apply when the form is maximized. If , the default margin is used.

Returns: TForm. The form instance with the specified maximized margin applied.

Static member MaximizedMargin<TForm>(form, margin)

Sets the maximized margin for the specified form using the provided margin values.

ParameterTypeDescription
TFormThe type of the form, which must derive from Form.
formTFormThe form whose maximized margin is to be set. Cannot be .
marginInt32[]An array of integers specifying the margin values. The array must contain either: 1 element (applied to all sides), 2 elements (horizontal and vertical), or 4 elements (left, top, right, bottom). Cannot be .

Returns: TForm. The form instance with the updated maximized margin, allowing for method chaining.

This extension method allows you to configure the maximized margin of a form in a flexible way. The method modifies the MaximizedMargin property based on the provided margin values. Throws:

Static member MdiParent<TForm>(form, value)

Sets the MdiParent property of the form.

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form instance on which to set the property.
valueFormThe parent form to be set as the MDI parent.

Returns: TForm. The form instance with the updated property.

This method allows you to fluently set the MdiParent property.

Static member OnActivated<TForm>(form, action)

Attaches an action to the Activated event of a form.

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form to attach the event handler to.
actionAction<TForm>The action to execute when the form is activated.

Returns: TForm. 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.


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

Static member OnClosed<TForm>(form, action)

Attaches an action to the Closed event of a form.

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form to attach the event handler to.
actionAction<TForm>The action to execute when the form is closed.

Returns: TForm. 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.


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

Static member OnClosing<TForm>(form, action)

Attaches an action to the Closing event of a form.

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form to attach the event handler to.
actionAction<TForm, CancelEventArgs>The action to execute when the form is closing. The CancelEventArgs parameter allows you to cancel the closing event.

Returns: TForm. 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.


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

Static member OnDeactivate<TForm>(form, action)

Attaches an action to the Deactivate event of a form.

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form to attach the event handler to.
actionAction<TForm>The action to execute when the form is deactivated.

Returns: TForm. 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.


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

Static member OnLoad<TForm>(form, action)

Attaches an action to the Load event of a form.

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form to attach the event handler to.
actionAction<TForm>The action to execute when the form is loaded.

Returns: TForm. 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.


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

Static member OnMdiChildActivate<TForm>(form, action)

Subscribes an action to the MdiChildActivate event of the form.

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form instance on which to subscribe the event.
actionAction<TForm>The action to be executed when the MDI child is activated.

Returns: TForm. The form instance with the event subscription.

This method allows you to fluently subscribe to the MdiChildActivate event.


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

Static member ShowInTaskbar<TForm>(form, value)

Sets the ShowInTaskbar property of the form.

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form instance on which to set the property.
valueBooleanA boolean value indicating whether the form is shown in the Windows taskbar.

Returns: TForm. The form instance with the updated property.

This method allows you to fluently set the ShowInTaskbar property.

Static member ShowModalMask<TForm>(form, value)

Sets the ShowModalMask property of the form.

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form instance on which to set the property.
valueBooleanA boolean value indicating whether to show a modal mask.

Returns: TForm. The form instance with the updated property.

This method allows you to fluently set the ShowModalMask property.

Static member StartPosition<TForm>(form, startPosition)

Sets the start position for the specified Form control, determining the initial position of the form when it is displayed.

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form for which to set the start position.
startPositionFormStartPositionThe start position to be applied to the form, specified as a FormStartPosition value.

Returns: TForm. 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.


myForm.StartPosition(FormStartPosition.CenterScreen);

Static member TopLevel<TForm>(form, value)

Sets the TopLevel property of the form.

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form instance on which to set the property.
valueBooleanA boolean value indicating whether the form is a top-level window.

Returns: TForm. The form instance with the updated property.

This method allows you to fluently set the TopLevel property.

Static member WindowState<TForm>(form, windowState)

Sets the window state for the specified Form control.

ParameterTypeDescription
TFormThe type of the form, which must inherit from Form.
formTFormThe form for which to set the window state.
windowStateFormWindowStateThe window state to be applied to the form, specified as a FormWindowState value.

Returns: TForm. 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.


myForm.WindowState(FormWindowState.Maximized);