BaseForm Class

A base form that provides some additional functionality compared to Form, and contains also some bug fixes.

Definition

Namespace: KGySoft.WinForms.Forms
Assembly: KGySoft.WinForms (in KGySoft.WinForms.dll) Version: 5.0.1
C#
public class BaseForm : Form
Inheritance
Object    MarshalByRefObject    Component    Control    ScrollableControl    ContainerControl    Form    BaseForm
Derived

Remarks

The BaseForm class provides the following features and changes:

  Tip

See also the example application that contains multiple examples for BaseForm features, such as the fixed font scaling, dynamic localization, MDI forms handling, etc. At the Releases page of the project repository you can download it as executable binaries as well.

Constructors

BaseForm Creates a new instance of BaseForm

Properties

AutoScaleFont Gets or sets whether the Font should be automatically scaled when DPI changes and the current thread has per-monitor DPI awareness.
Default value: .
CommandBindings Gets the command bindings of this form. Being a WinFormsCommandBindingsCollection, the Add methods also add the PropertyCommandStateUpdater to the created bindings.
See the GitHub documentation for details.
DeviceScale Gets the current scale of the form's display device. Before loading the form, or when per-monitor DPI awareness is not enabled, this property returns the system scale of the primary display, which is the same as the ScaleHelper.SystemScale property.
DynamicStringLocalization Gets or sets the dynamic string localization strategy of the form. It allows using potentially auto-generated string resources from .resx files.

See the online help for an example.
FontGets or sets the font of the text displayed by the control.
(Overrides ControlFont)
IconGets or sets the icon for the form.
IsDesignMode Gets whether the form is in design mode. Unlike the DesignMode property, this property works even during initialization.
IsLoaded Gets whether the form has already been loaded. This property is after the Load event is raised for the first time, and remains even if the form is shown as a dialog multiple times or the handle is recreated (e.g. because RightToLeft changes). Can be useful if you override the OnLoad method, and you want to avoid executing some initialization more than once.
IsSuspended Gets whether the form is suspended by an owned MDI child.
MdiClient Gets the corresponding MDI client of the form, or , if this form is neither an MDI container nor an MDI child.
OwnedMdiChildren Gets the forms that were shown as MDI children by the ShowMdiChild method.
SuspendingMdiChild Gets the MDI child that is suspending this form by a ShowMdiChild call, or if this form is not suspended. When this property is not , the returned form is among the elements of the OwnedMdiChildren property.
ToolTip Gets a ToolTip instance that can be used to show tooltips for controls of this form.
TranslateControls Gets or sets whether the form should translate its controls.
This property is obsolete. Use the DynamicStringLocalization property or override the ApplyResources and/or ApplyStringResources methods.
Obsolete

Methods

ApplyResources Applies the resources of the form. The default implementation just calls the ApplyStringResources method. Called when the form is loaded for the first time. In a derived form, this method can be overridden to apply additional (non-string) resources, and it can be called whenever the form's resources should be re-applied, e.g. when the display language changes.
ApplyStringResources Applies the string resources of the form. If the DynamicStringLocalization property is not set to Disabled, the default implementation just calls the LocalizationHelper.ApplyStringResources method. In a derived form, this method can be overridden to apply a custom string localization, and it can be called whenever the form's string resources should be re-applied, e.g. when the display language changes.
See the Remarks section of the DynamicStringLocalization property for more details.
Dispose Disposes the form and its resources.
(Overrides FormDispose(Boolean))
GetScaledBoundsRetrieves the bounds within which the control is scaled.
(Overrides FormGetScaledBounds(Rectangle, SizeF, BoundsSpecified))
InvalidateMdiClientArea Invalidates the MDI client area. Has effect only if the IsMdiContainer or IsMdiChild is for this form.
InvokeOnUIThread Invokes the specified callback on the thread that the control was created on.
OnCalledMdiChildClosed Raises the CalledMdiChildClosed event.
This method is obsolete along with the CalledMdiChildClosed event. Use the OwnedMdiChildClosed event and the OnOwnedMdiChildClosed method instead.
Obsolete
OnDeviceScaleAutoResized Raises the DeviceScaleAutoResized event.
See the Remarks section of the DeviceScaleAutoResized event for more details.
OnDeviceScaleChanged Raises the DeviceScaleChanged event.
See the Remarks section of the DeviceScaleChanged event for more details.
OnDeviceScaleChanging Raises the DeviceScaleChanging event.
See the Remarks section of the DeviceScaleChanging event for more details.
OnDeviceScaleGetNewSize Raises the DeviceScaleGetNewSize event.
See the Remarks section of the DeviceScaleGetNewSize event for more details.
OnDynamicStringLocalizationChanged Raises the DynamicStringLocalizationChanged event.
OnFontChangedRaises the FontChanged event.
(Overrides FormOnFontChanged(EventArgs))
OnHandleCreatedRaises the HandleCreated event.
(Overrides FormOnHandleCreated(EventArgs))
OnLoadRaises the Load event.
(Overrides FormOnLoad(EventArgs))
OnOwnedMdiChildClosed Raises the OwnedMdiChildClosed event.
OnParentChangedRaises the ParentChanged event.
(Overrides ContainerControlOnParentChanged(EventArgs))
OnParentFontChangedRaises the FontChanged event when the Font property value of the control's container changes.
(Overrides ControlOnParentFontChanged(EventArgs))
OnResumed Raises the Resumed event.
OnSuspended Raises the Suspended event.
PerformTranslate Translates the controls and tooltips of the given control.
Obsolete
ShowMdiChild Shows the form as an MDI child, owned by of this BaseForm. This BaseForm must be either an MDI container or another MDI child.
WndProcProcesses Windows messages.
(Overrides FormWndProc(Message))

Events

CalledMdiChildClosed Occurs when an MDI child shown by a ShowMdiChild method call is closed.
Obsolete
DeviceScaleAutoResized Occurs with per-monitor DPI awareness, when the form is resized automatically after the DeviceScaleChanged event.
DeviceScaleChanged Occurs with per-monitor DPI awareness, when the scale of the form's display device changes, after performing the default processing of the corresponding Windows message. On platform targets where the DpiChanged event exists, this event is raised after DpiChanged.
DeviceScaleChanging Occurs with per-monitor DPI awareness, when the scale of the form's display device changes, before performing the default processing of the corresponding Windows message. On platform targets where the DpiChanged event exists, this event is raised before DpiChanged.
DeviceScaleGetNewSize Occurs with per-monitor DPI awareness V2, before calculating the suggested bounds for the DeviceScaleChanging and DeviceScaleChanged events. Similar to the Form.OnGetDpiScaledSize method, but this is available also as an event for all .NET versions, and it does not cache the result.
DynamicStringLocalizationChanged Occurs when the DynamicStringLocalization property has changed.
OwnedMdiChildClosed Occurs when an MDI child shown by the ShowMdiChild method is closed.
PaintMdiClientArea Occurs when MDI area of the form has to be repainted. IsMdiContainer must be true to access this event.
Obsolete
Resumed Occurs when the MDI Child window called by ShowMdiChild that suspended the caller instance is closed.
Suspended Occurs when an MDI Child window called by ShowMdiChild suspends the caller instance.

Extension Methods

GetFormatFlags Gets the formatting flags for the text of a custom drawn control.
(Defined by ControlExtensions)
GetScale Gets the current scale factor of the specified control. If per-monitor DPI awareness is not enabled, it always returns SystemScale.
(Defined by ScaleHelper)
GetScrollBarSize Gets the recommended width and height of scrollbars matching the current scaling of the specified control.
(Defined by ScaleHelper)
HasDefaultScaling Gets whether the display that the specified control belongs to has the same DPI as the initial DPI of the primary display.
(Defined by ScaleHelper)
ScaleHeight Scales the specified height by the vertical scale factor of the control.
(Defined by ScaleHelper)
ScaleSize Scales the specified size by the scale factor of the control.
(Defined by ScaleHelper)
ScaleWidth Scales the specified width by the horizontal scale factor of the control.
(Defined by ScaleHelper)
SetControlEnabled Sets the Enabled property of the child controls within the specified root control, or the Enabled property of the specified control itself, if it is not a recognized container control. By this way pages of a TabControl will remain selectable, a SplitContainer remains resizable, etc.
(Defined by ControlExtensions)
SetControlReadonly Recursively sets the read-only state in the children of the specified root control. Affects TextBoxBase and IReadOnlyCapable instances.
(Defined by ControlExtensions)
SetDoubleBuffered Sets the double buffered state of a control
(Defined by ControlExtensions)
SetStyle Sets a specified ControlStyles flag to either or . It calls the protected Control.SetStyle method on the specified control as if it was a public method.
(Defined by ControlExtensions)

See Also