TMlSkinSwitchButton

A toggle switch for on/off state — a graphical stand-in for a check box.

Category
Buttons & toolbars
Unit
uMlSkinSwitchButton.pas
Inherits from
TMlSkinCustomControl

Notes

  • Read and write the state through Checked; OnChanged fires when it changes.
  • Each state can have its own image: ImageON and ImageOFF. Without images the switch is drawn from Color.
  • Text can sit next to the switch: CaptionON and CaptionOFF per state, with CaptionAlign placing it left or right.

Example

From the demo MlSkin.MainDemo.v3.0 (.dfm form file)

object mlsknswtchbtn1: TMlSkinSwitchButton
  Left = 656
  Top = 152
  Width = 34
  Height = 18
  ImageOFF.Active = True
  ImageOFF.Image = 'MlSkinSwitch_off'
  ImageOFF.Normal = 0
  ImageOFF.Hot = 1
  ImageOFF.Disable = 0
  ImageOFF.Count = 3
  ImageOFF.Pressed = 2
  ImageON.Active = True
  ImageON.Image = 'MlSkinSwitch_on'
  ImageON.Normal = 0
  ImageON.Hot = 1
  ImageON.Disable = 0
  ImageON.Count = 3
  ImageON.Pressed = 2
  Checked = True

Properties 10

NameTypeDefaultDescription
CanFocusedBooleanTrueWhether the control can take focus. With it off, clicking does not steal focus and Tab skips it.
ImageOFFTPngPictures—Image for the OFF state.
ImageONTPngPictures—Image for the ON state.
CheckedBooleanFalseThe switch state; True means on. Changing it fires OnChanged.
CustomDrawTSWBCustomDraw—Custom drawing settings, used to define how the switch is painted when no images are supplied.
CaptionVisibleBoolean—Whether the caption is drawn. Turn it off for icon-only buttons.
CaptionOFFstring—Text shown in the OFF state.
CaptionONstring—Text shown in the ON state.
CaptionAlignTMlSwitchButtonCaptionAlignsbcaLeftWhere the text sits: sbcaLeft to the left of the switch, sbcaRigth to the right.
ColorTColorclWhiteColor used when the switch is drawn without images.

Events 1

NameTypeDefaultDescription
OnChangedTNotifyEvent—Fires when the switch state changes.
Properties of TMlSkinCustomControl 4
NameTypeDefaultDescription
AboutTMlAboutInfo—A design-time property: double-clicking it in the Object Inspector opens the MLSkin about box with the component version. It has no effect at run time and is not stored in the .dfm.
TransparentBooleanTrueTransparent background: the control skips its own fill and shows the form background (image or color) instead.
AutoInvalidateBooleanFalseRepaints automatically when the content changes. Turn it on if property changes do not show up.
EraseBackgroundBooleanFalseWhether the background is erased before painting; worth toggling if the control flickers.
Events of TMlSkinCustomControl 4
NameTypeDefaultDescription
OnDPIChangedTMlDPIChangedEvent—Fires when the screen DPI changes, for example when the window moves to a monitor with a different scaling — a good place to re-adjust anything you draw yourself.
OnBackgroundChangingTMlBackgroundEvent—Fires just before the background changes, giving you a chance to adjust what is drawn.
OnBackgroundChangedTMlCustomDrawEvent—Fires after the background has been drawn, so you can paint on top of it.
OnVisibleChangedTNotifyEvent—Fires when the control is shown or hidden.

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.