
DFLにToggleSwitchコントロールを追加しました。
WinRTのToggleSwitchがWin32デスクトップアプリで使えるか試していたのですが、 XAML Islandsを使わないとできないみたいでした。
そこでひとまず自作のコントロールにしました。
自作したのでWindows でのモーションには対応していませんが、 最低限必要なレスポンスを返すようには工夫してあります。
サンプルコード
冒頭のスクリーンショットはDFLのexamplesのコードなのですが、説明が複雑になるので、 ここではもっと簡単にしたコードとそのスクリーンショットを載せておきます。

import dfl; version(Have_dfl) // For DUB. { } else { pragma(lib, "dfl.lib"); } class MainForm : Form { private ToggleSwitch _sw1; private ToggleSwitch _sw2; private ToggleSwitch _sw3; private ToggleSwitch _sw4; this() { this.text = "ToggleSwitch example"; this.size = Size(200, 300); int y = 5; enum int step = 50; _sw1 = new ToggleSwitch; _sw1.location = Point(5, y); _sw1.isOn = true; // 初期値をonにする(default on) _sw1.toggle ~= (ToggleSwitch ts, ToggledEventArgs ea) { // 2番と3番のトグルスイッチの有効/無効を反転する _sw2.enabled = !_sw2.enabled; _sw3.enabled = !_sw3.enabled; _sw2.redraw(); _sw3.redraw(); }; _sw1.baseColorOn = Color.red; // On時のベースカラーを赤色にする _sw1.parent = this; y += step; _sw2 = new ToggleSwitch; _sw2.location = Point(5, y); _sw2.isOn = true; // 初期値をonにする(default on) _sw2.parent = this; y += step; _sw3 = new ToggleSwitch; _sw3.location = Point(5, y); _sw3.isOn = false; // 初期値をoffにする _sw3.parent = this; y += step; _sw4 = new ToggleSwitch; _sw4.location = Point(5, y); _sw4.isOn = false; // 初期値をoffにする _sw4.enabled = false; // 初期値を無効にする _sw4.parent = this; } } void main(string[] args) { Application.enableVisualStyles(); import dfl.internal.dpiaware; SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); Application.run(new MainForm()); }