Table of Contents

Class ExForm

Namespace
ExControls
Assembly
ExControls.dll

Extended form. With ExTitleBar as a direct child it replaces the system caption by the title bar.

public class ExForm : Form, IDropTarget, ISynchronizeInvoke, IWin32Window, IBindableComponent, IComponent, IDisposable, IContainerControl
Inheritance
ExForm
Implements
Inherited Members
Extension Methods

Remarks

The form uses WS_EX_COMPOSITED by default (UseCompositedPainting). An empty unfocused TextBox.PlaceholderText in it causes endless repainting of the whole form (the text flickers, WinForms draws it outside WM_PAINT) - use HintText instead.

At runtime a form with a custom title bar has the system frame only on the left, right and bottom, in the designer it has neither frame nor caption - the client area (ClientSize, which the designer saves) is the same in both. WinForms computes the form size from the window style, i.e. with the system caption; ExForm therefore recomputes it itself at runtime (SetClientSizeCore, client area estimate before the window is created, size of the new window in CreateParams, scaling).

Properties

CornersType

Gets or sets type of form corner. Default is FormCornersType.Default. Works only in Windows 11+.

[ExCategory(CategoryType.Appearance)]
[ExDescription("Gets or sets the corners of the window (Windows 11+).", true)]
public FormCornersType CornersType { get; set; }

Property Value

FormCornersType

CreateParams

Gets the required creation parameters when the control handle is created.

protected override CreateParams CreateParams { get; }

Property Value

CreateParams

A CreateParams that contains the required creation parameters when the handle to the control is created.

DarkTitleBar

Gets or sets whether form's titlebar uses dark mode. Default is false. Works only in Windows 10+; TitleBarBackColor takes precedence over it.

[ExDescription("Gets or sets whether form's titlebar uses dark mode.", true)]
[ExCategory(CategoryType.Appearance)]
public bool DarkTitleBar { get; set; }

Property Value

bool

FormStyle

Gets or sets system backdrop of the form. Default is FormStyle.Auto, the same caption as a plain Form has; FormStyle.Default turns the backdrop off, which makes the active caption black in dark mode. Works only in Windows 11+ and shows only in the system caption - not under ExTitleBar.

[ExCategory(CategoryType.Appearance)]
[ExDescription("Gets or sets the system backdrop of the window (Windows 11+). It shows only in the system caption, not under ExTitleBar.", true)]
public FormStyle FormStyle { get; set; }

Property Value

FormStyle

Site

Gets or sets the site of the control.

[Browsable(false)]
public override ISite? Site { get; set; }

Property Value

ISite

The ISite associated with the Control, if any.

TitleBar

Gets the title bar replacing the system caption (first ExTitleBar among direct children).

[Browsable(false)]
public ExTitleBar? TitleBar { get; }

Property Value

ExTitleBar

TitleBarBackColor

Gets or sets background color of the titlebar. Set Color.Empty for default color. The system caption uses it in Windows 11+, ExTitleBar in Windows 10+.

[ExCategory(CategoryType.Appearance)]
[ExDescription("Gets or sets the background of the caption (system caption in Windows 11+, ExTitleBar in Windows 10+). Color.Empty uses the system color.", true)]
public Color TitleBarBackColor { get; set; }

Property Value

Color

TitleBarBorderColor

Gets or sets color of the window border. Set Color.Empty for default color. Works only in Windows 11+ (also with ExTitleBar).

[ExCategory(CategoryType.Appearance)]
[ExDescription("Gets or sets the color of the window border (Windows 11+). Color.Empty uses the system color.", true)]
public Color TitleBarBorderColor { get; set; }

Property Value

Color

TitleBarForeColor

Gets or sets foreground color of the titlebar. Set Color.Empty for default color. The system caption uses it in Windows 11+, ExTitleBar in Windows 10+ (text and window buttons).

[ExCategory(CategoryType.Appearance)]
[ExDescription("Gets or sets the text color of the caption (system caption in Windows 11+, ExTitleBar in Windows 10+). Color.Empty uses the system color.", true)]
public Color TitleBarForeColor { get; set; }

Property Value

Color

UseCompositedPainting

Gets or sets whether the whole form is painted double buffered (WS_EX_COMPOSITED) - less flicker when resizing, but some controls repaint endlessly in such a window (TextBox.PlaceholderText). Default is true.

[ExCategory(CategoryType.WindowStyle)]
[ExDescription("Gets or sets whether the whole form is painted double buffered (WS_EX_COMPOSITED).", true)]
public bool UseCompositedPainting { get; set; }

Property Value

bool

UsesCustomTitleBar

Gets whether the form shows TitleBar instead of the system caption: the title bar is visible, the form is a top-level window with a border (any FormBorderStyle except None) and the system is Windows 10+ (SupportsCustomTitleBar). The designer shows such a form without the system caption and frame.

[Browsable(false)]
public bool UsesCustomTitleBar { get; }

Property Value

bool

Methods

GetScaledBounds(Rectangle, SizeF, BoundsSpecified)

Retrieves the bounds within which the control is scaled.

protected override Rectangle GetScaledBounds(Rectangle bounds, SizeF factor, BoundsSpecified specified)

Parameters

bounds Rectangle

A Rectangle that specifies the area for which to retrieve the display bounds.

factor SizeF

The height and width of the control's bounds.

specified BoundsSpecified

One of the values of BoundsSpecified that specifies the bounds of the control to use when defining its size and position.

Returns

Rectangle

A Rectangle representing the bounds within which the control is scaled.

Remarks

A form with a custom title bar scales the client area without the system caption.

OnControlAdded(ControlEventArgs)

Raises the ControlAdded event.

protected override void OnControlAdded(ControlEventArgs e)

Parameters

e ControlEventArgs

A ControlEventArgs that contains the event data.

OnControlRemoved(ControlEventArgs)

Raises the ControlRemoved event.

protected override void OnControlRemoved(ControlEventArgs e)

Parameters

e ControlEventArgs

A ControlEventArgs that contains the event data.

OnHandleCreated(EventArgs)

Raises the HandleCreated event.

protected override void OnHandleCreated(EventArgs e)

Parameters

e EventArgs

An EventArgs that contains the event data.

OnResize(EventArgs)

Raises the Resize event.

protected override void OnResize(EventArgs e)

Parameters

e EventArgs

An EventArgs that contains the event data.

OnStyleChanged(EventArgs)

Raises the StyleChanged event.

protected override void OnStyleChanged(EventArgs e)

Parameters

e EventArgs

An EventArgs that contains the event data.

SetBoundsCore(int, int, int, int, BoundsSpecified)

Performs the work of setting the specified bounds of this control.

protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)

Parameters

x int

The new Left property value of the control.

y int

The new Top property value of the control.

width int

The new Width property value of the control.

height int

The new Height property value of the control.

specified BoundsSpecified

A bitwise combination of the BoundsSpecified values.

SetClientSizeCore(int, int)

Sets the client size of the form. This will adjust the bounds of the form to make the client size the requested size.

protected override void SetClientSizeCore(int x, int y)

Parameters

x int

Requested width of the client region.

y int

Requested height of the client region.

SizeFromClientSize(Size)

Determines the size of the entire control from the height and width of its client area.

protected override Size SizeFromClientSize(Size clientSize)

Parameters

clientSize Size

A Size value representing the height and width of the control's client area.

Returns

Size

A Size value representing the height and width of the entire control.

Remarks

A form with a custom title bar has the system frame only on the left, right and bottom.

WndProc(ref Message)

Processes Windows messages.

protected override void WndProc(ref Message m)

Parameters

m Message

The Windows Message to process.