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.
Notes
- Put it at the top of a
TMlSkinFormform (Align = alTopand height 48 by default). At run time it setsTMlSkinForm.TitleHeightto 0 to hide the original title bar (HideSkinTitle) and registers itself as the form'sCustomTitleBar. - The middle area can host toolbars, search boxes and other controls; give a child
Align = alClientto 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
HTTRANSPARENTfrom its ownWM_NCHITTESTover its empty parts. - Custom buttons added to
Buttonssit left of the minimize button. Colors come fromGlyphColor,HotColor,DownColorandCloseHotColor; for light / dark mode just switch these andColor. - To draw the buttons differently (rounded tiles, say), paint the background in
OnDrawButton, callDrawButtonGlyph(Bitmap, Kind, R, Color)for the stock line glyph, and setHandled := 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
| Name | Type | Default | Description |
|---|---|---|---|
SkinForm | TMlSkinForm | — | 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. |
Logo | TMlResID | — | Resource ID of the logo shown left of the caption. |
LogoColor | TColor | clNone | Logo 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. |
ShowCaption | Boolean | True | Whether the caption text (Caption) is shown. |
ShowLogo | Boolean | True | Whether the logo is drawn. Turning it off keeps the Logo setting; the caption then moves left to PaddingLeft. |
CaptionOffsetY | Integer | 0 | Vertical 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. |
PaddingLeft | Integer | 12 | Gap between the left edge and the logo (or caption), default 12. |
PaddingRight | Integer | 0 | Gap 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. |
Buttons | TMlTitleBarButtons | — | Custom buttons (TMlTitleBarButton) placed left of the minimize button, each with its own icon, hint and OnClick. |
ButtonWidth | Integer | 46 | Width 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. |
GlyphColor | TColor | $00706860 | Color of the —/□/X button glyphs. |
HotColor | TColor | $00F4F2F0 | Button background when hovered (except the close button). |
DownColor | TColor | $00EBE7E4 | Button background while pressed. |
CloseHotColor | TColor | $002311E8 | Close-button background when hovered, red by default; the cross turns white. |
BorderBottom | Boolean | True | Whether a divider line is drawn along the bottom (in BorderColor). |
BorderColor | TColor | $00EBE7E4 | Color of the bottom divider. |
ShowMinimize | Boolean | True | Whether the minimize button is shown. |
ShowMaximize | Boolean | True | Whether the maximize / restore button is shown. |
ShowClose | Boolean | True | Whether the close button is shown. |
HideSkinTitle | Boolean | True | Whether 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. |
FrameColor | TColor | $00C4C0BC | Color 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
| Name | Type | Default | Description |
|---|---|---|---|
OnDrawButton | TMlTitleBarDrawButtonEvent | — | 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.