Checkboxes
Part of DflCategory
Description
Demonstrates getting and setting the state of the checkboxes.
Example
import dfl.all; /* Program constants */ const char[] defaultPath = "C:\\Program Files\\jcc7"; const char[] pgmName = "Checkbox Example"; int main() { Form frmMain; CheckBox chk1, chk2, chk3, chk4, chk5, chk6, chk7, chk8; TextBox txtPath; Label lblInstruct; Button btnBrowse, btnInstall, btnCheckAll, btnCheckNone; void bntInstall_onClick(Object sender, EventArgs ea) { char[] installPath = txtPath.text ~ "\\"; MessageBox.show(installPath, "txtPath"); if(chk1.checkState == CheckState.CHECKED) MessageBox.show("Part 1 checked", pgmName); if(chk2.checkState == CheckState.CHECKED) MessageBox.show("Part 2 checked", pgmName); if(chk3.checkState == CheckState.CHECKED) MessageBox.show("Part 3 checked", pgmName); if(chk4.checkState == CheckState.CHECKED) MessageBox.show("Part 4 checked", pgmName); if(chk5.checkState == CheckState.CHECKED) MessageBox.show("Part 5 checked", pgmName); if(chk6.checkState == CheckState.CHECKED) MessageBox.show("Part 6 checked", pgmName); if(chk7.checkState == CheckState.CHECKED) MessageBox.show("Part 7 checked", pgmName); if(chk8.checkState == CheckState.CHECKED) MessageBox.show("Part 8 checked", pgmName); } void bntCheckNone_onClick(Object sender, EventArgs ea) { chk1.checkState(CheckState.UNCHECKED); chk2.checkState(CheckState.UNCHECKED); chk3.checkState(CheckState.UNCHECKED); chk4.checkState(CheckState.UNCHECKED); chk5.checkState(CheckState.UNCHECKED); chk6.checkState(CheckState.UNCHECKED); chk7.checkState(CheckState.UNCHECKED); chk8.checkState(CheckState.UNCHECKED); } void bntCheckAll_onClick(Object sender, EventArgs ea) { chk1.checkState(CheckState.CHECKED); chk2.checkState(CheckState.CHECKED); chk3.checkState(CheckState.CHECKED); chk4.checkState(CheckState.CHECKED); chk5.checkState(CheckState.CHECKED); chk6.checkState(CheckState.CHECKED); chk7.checkState(CheckState.CHECKED); chk8.checkState(CheckState.CHECKED); } void bntBrowse_onClick(Object sender, EventArgs ea) { MessageBox.show("You clicked on browse.", pgmName); } frmMain = new Form; frmMain.text = "Checkboxes"; frmMain.size = Size(450, 380); frmMain.formBorderStyle = FormBorderStyle.FIXED_SINGLE; txtPath = new TextBox; txtPath.size = Size(400, 20); txtPath.text = defaultPath; txtPath.top = 15; txtPath.left = 15; txtPath.parent = frmMain; btnBrowse = new Button; btnBrowse.size = Size(80, 20); btnBrowse.text = "Browse..."; btnBrowse.top = 35; btnBrowse.left = 15; btnBrowse.parent = frmMain; btnBrowse.click ~= &bntBrowse_onClick; lblInstruct = new Label; lblInstruct.size = Size(300, 20); lblInstruct.text = "Select parts to install: "; lblInstruct.top = 70; lblInstruct.left = 15; lblInstruct.parent = frmMain; chk1 = new CheckBox; chk1.text = "Part 1"; chk1.size = Size(100, 25); chk1.top = 85; chk1.left = 15; chk1.parent = frmMain; chk2 = new CheckBox; chk2.text = "Part 2"; chk2.size = Size(100, 25); chk2.top = 110; chk2.left = 15; chk2.parent = frmMain; chk3 = new CheckBox; chk3.text = "Part 3"; chk3.size = Size(100, 25); chk3.top = 135; chk3.left = 15; chk3.parent = frmMain; chk4 = new CheckBox; chk4.text = "Part 4"; chk4.size = Size(100, 25); chk4.top = 160; chk4.left = 15; chk4.parent = frmMain; chk5 = new CheckBox; chk5.text = "Part 5"; chk5.size = Size(100, 25); chk5.top = 185; chk5.left = 15; chk5.parent = frmMain; chk6 = new CheckBox; chk6.text = "Part 6"; chk6.size = Size(100, 25); chk6.top = 210; chk6.left = 15; chk6.parent = frmMain; chk7 = new CheckBox; chk7.text = "Part 7"; chk7.size = Size(100, 25); chk7.top = 235; chk7.left = 15; chk7.parent = frmMain; chk8 = new CheckBox; chk8.text = "Part 8"; chk8.size = Size(100, 25); chk8.top = 260; chk8.left = 15; chk8.parent = frmMain; btnCheckAll = new Button; btnCheckAll.text = "Check All"; btnCheckAll.size = Size(100, 25); btnCheckAll.top = 230; btnCheckAll.left = 200; btnCheckAll.parent = frmMain; btnCheckAll.click ~= &bntCheckAll_onClick; btnCheckNone = new Button; btnCheckNone.text = "Uncheck All"; btnCheckNone.size = Size(100, 25); btnCheckNone.top = 260; btnCheckNone.left = 200; btnCheckNone.parent = frmMain; btnCheckNone.click ~= &bntCheckNone_onClick; btnInstall = new Button; btnInstall.text = "Install"; btnInstall.size = Size(100, 25); btnInstall.top = 300; btnInstall.left = 15; btnInstall.parent = frmMain; btnInstall.click ~= &bntInstall_onClick; Application.run(frmMain); return 0; }
Sample Batch File
@echo off dmd checkboxes.d -L/exet:nt/su:windows:4.0 ..\dfl.lib -I.. checkboxes.exe pause
Tested Versions
I've tested it with DFL 0.7 and DMD 0.106.
In order to compile this code with more recent DFL versions, you'll need to change "MessageBox.show" to "msgBox".