Table of Contents

Class ExTitleBar

Namespace
ExControls
Assembly
ExControls.dll

Custom title bar of an ExForm. As a direct child of the form (docked to the top) it replaces the system caption: the window icon (system menu) on the left, the window buttons on the right, the title bar controls (e.g. the main menu) between them and the form text in the free space. The free space and empty parts of tool strips drag the window, their items stay clickable.

[ToolboxBitmap(typeof(ToolboxIcons), "Toolbox.ExTitleBar.ico")]
public class ExTitleBar : Panel, IDropTarget, ISynchronizeInvoke, IWin32Window, IBindableComponent, IComponent, IDisposable, IThemeable
Inheritance
ExTitleBar
Implements
Inherited Members
Extension Methods

Remarks

Only tool strips directly in the title bar are handled (their items are always laid out side by side); other controls in the title bar are clickable as a whole. An inactive form has dimmed text, button glyphs and also menu items and labels in these tool strips (like a system menu bar)

  • through ForeColor, so a renderer that determines the text color of items itself does not show the dimming. The buttons and the icon follow the system caption: help (HelpButton) only without minimize and maximize, a tool window only close, a dialog (FixedDialog) without its own icon has no icon. The caption colors of the form (TitleBarBackColor, TitleBarForeColor) and in an active form the Windows accent color (if the system shows it on title bars) take precedence over the colors of the title bar; tool strips in the title bar then have a transparent background and text in the caption color, other controls keep their colors. A menu (MenuStrip) whose items do not fit into the title bar collapses at runtime into a ☰ button (CollapseMenu). When the form does not use the custom title bar (UsesCustomTitleBar), it is a plain panel without icon, text and buttons.

Constructors

ExTitleBar()

Creates a title bar docked to the top.

public ExTitleBar()

Properties

AutoSize

Gets or sets whether the height of the title bar follows its controls (at least 32 px at 96 DPI).

[Browsable(true)]
public override bool AutoSize { get; set; }

Property Value

bool

ButtonHoverBackColor

Gets or sets the background of a window button under the mouse. Color.Empty derives it from BackColor and ForeColor.

[ExCategory(CategoryType.Appearance)]
[ExDescription("Gets or sets the background of a window button under the mouse. Color.Empty derives it from BackColor and ForeColor.", true)]
public Color ButtonHoverBackColor { get; set; }

Property Value

Color

ButtonPressedBackColor

Gets or sets the background of a pressed window button. Color.Empty derives it from BackColor and ForeColor.

[ExCategory(CategoryType.Appearance)]
[ExDescription("Gets or sets the background of a pressed window button. Color.Empty derives it from BackColor and ForeColor.", true)]
public Color ButtonPressedBackColor { get; set; }

Property Value

Color

CloseButtonHoverBackColor

Gets or sets the background of the close button under the mouse. Color.Empty is the red of the system caption (Windows 11 or Windows 10).

[ExCategory(CategoryType.Appearance)]
[ExDescription("Gets or sets the background of the close button under the mouse. Color.Empty is the red of the system caption.", true)]
public Color CloseButtonHoverBackColor { get; set; }

Property Value

Color

CollapseMenu

Gets or sets whether a menu in the title bar collapses into one button (☰) when the title bar is too narrow for all its menu items (only at runtime).

[ExCategory(CategoryType.Behavior)]
[ExDescription("Gets or sets whether a menu in the title bar collapses into one button when the title bar is too narrow for its items.", true)]
public bool CollapseMenu { get; set; }

Property Value

bool

DefaultSize

Gets the default size of the control.

protected override Size DefaultSize { get; }

Property Value

Size

The default Size of the control.

DisplayRectangle

Gets the rectangle that represents the virtual display area of the control.

public override Rectangle DisplayRectangle { get; }

Property Value

Rectangle

A Rectangle that represents the display area of the control.

Remarks

The title bar controls are laid out between the icon and the window buttons.

Dock

Gets or sets which control borders are docked to its parent control and determines how a control is resized with its parent.

public override DockStyle Dock { get; set; }

Property Value

DockStyle

One of the DockStyle values. The default is None.

Exceptions

InvalidEnumArgumentException

The value assigned is not one of the DockStyle values.

InactiveForeColor

Gets or sets the color of the text and button glyphs of an inactive form. Color.Empty derives it from ForeColor.

[ExCategory(CategoryType.Appearance)]
[ExDescription("Gets or sets the color of the text and button glyphs of an inactive form. Color.Empty derives it from ForeColor.", true)]
public Color InactiveForeColor { get; set; }

Property Value

Color

ShowTitle

Gets or sets whether the title bar shows the form's text in the free space between its controls (in the font of the system caption).

[ExCategory(CategoryType.Appearance)]
[ExDescription("Gets or sets whether the title bar shows the form's text in the free space between its controls.", true)]
public bool ShowTitle { get; set; }

Property Value

bool

TopBorderColor

Gets or sets the 1 px top border of the window in Windows 10 (Windows 11 draws it itself). Color.Empty derives it from BackColor and ForeColor.

[ExCategory(CategoryType.Appearance)]
[ExDescription("Gets or sets the 1 px top border of the window in Windows 10. Color.Empty derives it from BackColor and ForeColor.", true)]
public Color TopBorderColor { get; set; }

Property Value

Color

Methods

ApplyTheme(ExTheme)

Sets the title bar colors by the theme (panel background and text) and applies the theme to the controls in the title bar.

public void ApplyTheme(ExTheme theme)

Parameters

theme ExTheme

theme to apply

Dispose(bool)

Releases the unmanaged resources used by the Control and its child controls and optionally releases the managed resources.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

GetPreferredSize(Size)

Height by the title bar controls (with AutoSize): the tallest visible control with padding, at least 32 px at 96 DPI.

public override Size GetPreferredSize(Size proposedSize)

Parameters

proposedSize Size

proposed size (ignored, the title bar keeps its width)

Returns

Size

HitTest(Point)

Determines the part of the title bar at a point.

public TitleBarHit HitTest(Point point)

Parameters

point Point

point in client coordinates of the title bar

Returns

TitleBarHit

OnBackColorChanged(EventArgs)

Raises the BackColorChanged event.

protected override void OnBackColorChanged(EventArgs e)

Parameters

e EventArgs

An EventArgs that contains the event data.

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.

OnForeColorChanged(EventArgs)

Raises the ForeColorChanged event.

protected override void OnForeColorChanged(EventArgs e)

Parameters

e EventArgs

An EventArgs that contains the event data.

OnLayout(LayoutEventArgs)

Raises the Layout event.

protected override void OnLayout(LayoutEventArgs levent)

Parameters

levent LayoutEventArgs

A LayoutEventArgs that contains the event data.

OnPaint(PaintEventArgs)

Raises the Paint event.

protected override void OnPaint(PaintEventArgs e)

Parameters

e PaintEventArgs

A PaintEventArgs that contains the event data.

OnPaintBackground(PaintEventArgs)

Paints the background of the control.

protected override void OnPaintBackground(PaintEventArgs e)

Parameters

e PaintEventArgs

The event data.

Exceptions

ArgumentNullException

.NET 5 and later versions only: e is null.

OnParentChanged(EventArgs)

Raises the ParentChanged event.

protected override void OnParentChanged(EventArgs e)

Parameters

e EventArgs

An EventArgs that contains the event data.

SetVisibleCore(bool)

Sets the control to the specified visible state.

protected override void SetVisibleCore(bool value)

Parameters

value bool

true to make the control visible; otherwise, false.

WndProc(ref Message)

Processes Windows messages.

protected override void WndProc(ref Message m)

Parameters

m Message

The Windows Message to process.