Using a ToggleSwitch

We write the code corresponding to the OnChanged property of the TW3ToggleSwitch so that the outcome depends on its current Checked property. Use the toggle switch in the demonstration below to change the zoom of the memo.

Demonstration

If the demo does not work in your current browser, try another such as Chrome, Opera, Safari or Internet Explorer9. If you see no display at school, the security system might have blocked it. You can try instead this direct link to the program running on its own page.

ToggleSwitchDemo.html

Smart Pascal Code

unit Form1;

interface

uses 
  SmartCL.System, SmartCL.Graphics, SmartCL.Components, SmartCL.Forms, 
  SmartCL.Fonts, SmartCL.Borders, SmartCL.Application, SmartCL.Controls.ToggleSwitch,
  SmartCL.Controls.Panel, SmartCL.Controls.Memo, SmartCL.Controls.Label;

type
  TForm1 = class(TW3Form)
    procedure W3ToggleSwitch1Changed(Sender: TObject);
  private
    {$I 'Form1:intf'}
  protected
    procedure InitializeObject; override;
  end;

implementation

procedure TForm1.W3ToggleSwitch1Changed(Sender: TObject);
begin
  if W3ToggleSwitch1.Checked then
    W3Memo1.Zoom := 1.8
  else
    W3Memo1.Zoom := 1;
end;

procedure TForm1.InitializeObject;
begin
  inherited;
  {$I 'Form1:impl'}
  W3Memo1.Text := 'The default font for the memo might be a bit small for those '+
                  'with impaired vision. The toggle switch controls the zoom.';
  W3Memo1.ScrollH :=  soNone;
  W3Memo1.ScrollV :=  soNone;
  W3Label1.Font.Size := 20;
end;

initialization
  Forms.RegisterForm({$I %FILE%}, TForm1);
end.

XML Code of Form

<SMART>
  <Form version="2" subversion="1">
    <Created>2014-11-07T17:06:17.187</Created>
    <Modified>2014-11-07T17:49:36.108</Modified>
    <object type="TW3Form">
      <Caption>W3Form</Caption>
      <Name>Form1</Name>
      <object type="TW3ToggleSwitch">
        <Width>128</Width>
        <Top>176</Top>
        <Left>152</Left>
        <Height>32</Height>
        <Name>W3ToggleSwitch1</Name>
        <OnChanged>W3ToggleSwitch1Changed</OnChanged>
      </object>
      <object type="TW3Panel">
        <Width>424</Width>
        <Top>16</Top>
        <Left>8</Left>
        <Height>152</Height>
        <Name>W3Panel1</Name>
        <object type="TW3Memo">
          <Text>W3Memo</Text>
          <Width>216</Width>
          <Top>7</Top>
          <Left>8</Left>
          <Height>72</Height>
          <Name>W3Memo1</Name>
        </object>
      </object>
      <object type="TW3Label">
        <Caption>Magnifier</Caption>
        <Width>104</Width>
        <Top>176</Top>
        <Left>56</Left>
        <Height>32</Height>
        <Name>W3Label1</Name>
      </object>
    </object>
  </Form>
</SMART>

Programming - a skill for life!

How to use a range of visual components such as edit boxes, combo boxes, grids and charts on one or multiple forms (including a modal form)