FormExtensions
Namespace: Wisej.Web.Markup
Assembly: Wisej.Framework (4.1.0.0)
Adds fluent markup extension methods to the Form class.
- C#
- VB.NET
public class FormExtensions
Public Class FormExtensions
Methods
AcceptButton<TForm>(form, acceptButton)
Sets the accept button for the specified Form 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. | |
| form | TForm | The form for which to set the accept button. |
| acceptButton | Button | The 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);
AutoSize<TForm>(form, autoSize, mode)
Sets the AutoSize property and AutoSizeMode for the specified Form control, enabling or disabling automatic resizing.
| Parameter | Type | Description |
|---|---|---|
| TForm | The type of the form, which must inherit from Form. | |
| form | TForm | The form for which to set the AutoSize property and mode. |
| autoSize | Boolean | A boolean value indicating whether to enable automatic resizing. Default is false. |
| mode | AutoSizeMode | The 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);
CancelButton<TForm>(form, cancelButton)
Sets the cancel button for the specified Form 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. | |
| form | TForm | The form for which to set the cancel button. |
| cancelButton | Button | The 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);
Icon<TForm>(form, icon)
Sets the icon for the specified Form control.
| Parameter | Type | Description |
|---|---|---|
| TForm | The type of the form, which must inherit from Form. | |
| form | TForm | The form for which to set the icon. |
| icon | Image | The 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);
Icon<TForm>(form, iconSource)
Sets the icon for the specified Form control using the provided icon source.
| Parameter | Type | Description |
|---|---|---|
| TForm | The type of the form, which must inherit from Form. | |
| form | TForm | The form for which to set the icon. |
| iconSource | String | The 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");
IconLarge<TForm>(form, icon)
Sets the large icon for the specified Form control.
| Parameter | Type | Description |
|---|---|---|
| TForm | The type of the form, which must inherit from Form. | |
| form | TForm | The form for which to set the icon. |
| icon | Image | The 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);
IconLarge<TForm>(form, iconSource)
Sets the large icon for the specified Form control using the provided icon source.
| Parameter | Type | Description |
|---|---|---|
| TForm | The type of the form, which must inherit from Form. | |
| form | TForm | The form for which to set the large icon. |
| iconSource | String | The 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");
IsMdiContainer<TForm>(form, value)
Sets the IsMdiContainer property of the form.
| Parameter | Type | Description |
|---|---|---|
| TForm | The type of the form, which must inherit from Form. | |
| form | TForm | The form instance on which to set the property. |
| value | Boolean | A 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);
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. | |
| form | TForm | The form instance to configure. |
| value | Boolean | true 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.
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. | |
| form | TForm | The form instance to configure. |
| value | Boolean | true 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.
MaximizedMargin<TForm>(form, margin)
Sets the margin to be applied when the form is maximized and returns the form instance.
| Parameter | Type | Description |
|---|---|---|
| TForm | The type of the form, which must derive from Form. | |
| form | TForm | The form instance to which the maximized margin will be applied. |
| margin | Nullable<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.
MaximizedMargin<TForm>(form, margin)
Sets the maximized margin for the specified form using the provided margin values.
| Parameter | Type | Description |
|---|---|---|
| TForm | The type of the form, which must derive from Form. | |
| form | TForm | The form whose maximized margin is to be set. Cannot be . |
| margin | Int32[] | 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:
- ArgumentNullException Thrown if margin is .
- ArgumentException Thrown if margin does not contain 1, 2, or 4 elements.
MdiParent<TForm>(form, value)
Sets the MdiParent property of the form.
| Parameter | Type | Description |
|---|---|---|
| TForm | The type of the form, which must inherit from Form. | |
| form | TForm | The form instance on which to set the property. |
| value | Form | The 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.
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. | |
| form | TForm | The form to attach the event handler to. |
| action | Action<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");
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. | |
| form | TForm | The form to attach the event handler to. |
| action | Action<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"));
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. | |
| form | TForm | The form to attach the event handler to. |
| action | Action<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;
});
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. | |
| form | TForm | The form to attach the event handler to. |
| action | Action<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");
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. | |
| form | TForm | The form to attach the event handler to. |
| action | Action<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");
OnMdiChildActivate<TForm>(form, action)
Subscribes an action to the MdiChildActivate event of the form.
| Parameter | Type | Description |
|---|---|---|
| TForm | The type of the form, which must inherit from Form. | |
| form | TForm | The form instance on which to subscribe the event. |
| action | Action<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"));
ShowInTaskbar<TForm>(form, value)
Sets the ShowInTaskbar property of the form.
| Parameter | Type | Description |
|---|---|---|
| TForm | The type of the form, which must inherit from Form. | |
| form | TForm | The form instance on which to set the property. |
| value | Boolean | A 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.
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. | |
| form | TForm | The form instance on which to set the property. |
| value | Boolean | A 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.
StartPosition<TForm>(form, startPosition)
Sets the start position for the specified Form 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. | |
| form | TForm | The form for which to set the start position. |
| startPosition | FormStartPosition | The 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);
TopLevel<TForm>(form, value)
Sets the TopLevel property of the form.
| Parameter | Type | Description |
|---|---|---|
| TForm | The type of the form, which must inherit from Form. | |
| form | TForm | The form instance on which to set the property. |
| value | Boolean | A 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.
WindowState<TForm>(form, windowState)
Sets the window state for the specified Form control.
| Parameter | Type | Description |
|---|---|---|
| TForm | The type of the form, which must inherit from Form. | |
| form | TForm | The form for which to set the window state. |
| windowState | FormWindowState | The 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);