TMlSkinTitleBar

A client-area title bar that merges the window caption and a toolbar into one row: logo and caption on the left, minimize / maximize / close on the right, and any controls you like in between.

Category
Forms & borders
Unit
uMlSkinTitleBar.pas
Inherits from
TCustomControl

Notes

  • Put it at the top of a TMlSkinForm form (Align = alTop and height 48 by default). At run time it sets TMlSkinForm.TitleHeight to 0 to hide the original title bar (HideSkinTitle) and registers itself as the form's CustomTitleBar.
  • The middle area can host toolbars, search boxes and other controls; give a child Align = alClient to fill the space between the logo and the buttons.
  • Dragging empty space moves the window, double-clicking maximizes / restores, and dragging to a screen edge snaps — just like the system title bar. On a resizable form the top, left and right edges also resize the window. A windowed child in the middle that should also drag the window must return HTTRANSPARENT from its own WM_NCHITTEST over its empty parts.
  • Custom buttons added to Buttons sit left of the minimize button. Colors come from GlyphColor, HotColor, DownColor and CloseHotColor; for light / dark mode just switch these and Color.
  • To draw the buttons differently (rounded tiles, say), paint the background in OnDrawButton, call DrawButtonGlyph(Bitmap, Kind, R, Color) for the stock line glyph, and set Handled := True.
  • With rounded form corners (RoundCorner), the anti-aliased overlay for the two top corners takes its pixels from this control, so the title bar color blends into the rounded corners.

Example

From the demo MlSkin.Demo.TMlSkinTitleBar自定义标题栏.v5.x (.dfm form file)

object ttb1: TMlSkinTitleBar
  Left = 0
  Top = 0
  Width = 760
  Font.Charset = GB2312_CHARSET
  Font.Color = 5326563
  Font.Height = -15
  Font.Style = [fsBold]
  ParentFont = False
  ParentShowHint = False
  ShowHint = True
  LogoColor = 5326563
  Buttons = <
  ...

Properties 21

NameTypeDefaultDescription
SkinFormTMlSkinForm—The TMlSkinForm it works with. Left empty, the first TMlSkinForm on the form is found at run time, so you rarely need to set it.
LogoTMlResID—Resource ID of the logo shown left of the caption.
LogoColorTColorclNoneLogo tint. clNone (default) keeps the original colors; any other color recolors the logo while keeping its transparency — handy for following the theme color or dark mode.
ShowCaptionBooleanTrueWhether the caption text (Caption) is shown.
ShowLogoBooleanTrueWhether the logo is drawn. Turning it off keeps the Logo setting; the caption then moves left to PaddingLeft.
CaptionOffsetYInteger0Vertical offset of the caption (96-DPI pixels, scaled for DPI; negative moves up). 0 (default) centres it; use it to correct fonts that look slightly high or low.
PaddingLeftInteger12Gap between the left edge and the logo (or caption), default 12.
PaddingRightInteger0Gap between the rightmost button (close) and the right edge. 0 (default) puts the buttons flush, like the system title bar; leave a gap if you draw the buttons as rounded tiles.
ButtonsTMlTitleBarButtons—Custom buttons (TMlTitleBarButton) placed left of the minimize button, each with its own icon, hint and OnClick.
ButtonWidthInteger46Width of each button (96-DPI pixels, scaled for DPI), default 46 — the same as Windows title-bar buttons. Buttons are as tall as the title bar.
GlyphColorTColor$00706860Color of the —/□/X button glyphs.
HotColorTColor$00F4F2F0Button background when hovered (except the close button).
DownColorTColor$00EBE7E4Button background while pressed.
CloseHotColorTColor$002311E8Close-button background when hovered, red by default; the cross turns white.
BorderBottomBooleanTrueWhether a divider line is drawn along the bottom (in BorderColor).
BorderColorTColor$00EBE7E4Color of the bottom divider.
ShowMinimizeBooleanTrueWhether the minimize button is shown.
ShowMaximizeBooleanTrueWhether the maximize / restore button is shown.
ShowCloseBooleanTrueWhether the close button is shown.
HideSkinTitleBooleanTrueWhether SkinForm.TitleHeight is set to 0 at run time to hide MLSkin's own title bar. On by default; turn it off only if you want both title bars.
FrameColorTColor$00C4C0BCColor of the window frame. At run time it is passed to the SkinForm's FrameColor with KeepFrameColor on, so the sides, bottom, rounded corners and the title bar's top edge form one continuous ring. clNone leaves MLSkin's own frame drawing alone.

Events 1

NameTypeDefaultDescription
OnDrawButtonTMlTitleBarDrawButtonEvent—Custom button drawing, fired before each button (minimize, maximize, restore, close, custom) is painted; see TMlTitleBarDrawButtonEvent for the parameters. Set Handled := True to skip the default drawing; DrawButtonGlyph paints the stock line glyph.

Only the properties and events MLSkin adds are listed here. Standard VCL properties such as Align, Anchors, Font and OnClick are available too and behave exactly as on the stock controls.

Offline helpA PDF / CHM version is available for offline reading.