Attribute VB_Name = "RadioButtonDemoModule" Option Explicit '--------------------------------------------------------- 'RadioButtonDemo 'Shows the use of the WS_RADIO_BUTTON widget '--------------------------------------------------------- Public wsFactory As New WStFactory Public wsForm As New WStForm Public wsWidget As New WStWidget Public Sub Main() Dim bResult As Boolean Dim sObjectName As String Dim sEventValue As String Dim sCurrentState As String Dim sState As String Dim bEnd As Boolean Dim x As Integer Dim y As Integer Dim cx As Integer Dim cy As Integer bEnd = False wsFactory.CreateFormByName "myForm" wsForm.SetCoordTypeByName "myForm", WS_FORM_CT_BYPERCENTAGE 'Widget creation wsFactory.CreateWidget WS_LABEL, 0, "formTittle", 15, 0, 60, 5, "Radio Button Demo" wsFactory.CreateWidget WS_BUTTON, 0, "exitButton", 12, 80, 32, 12, "Exit" wsFactory.CreateWidget WS_BUTTON, 0, "clearButton", 55, 80, 32, 12, "Reset" x = 10 y = 10 cx = 35 cy = 10 wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "myRadioButton", x, y, cx, cy, "RB Test 1" wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "myRadioButton2", x, y + 15, cx, cy, "RB Test 2" wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "myRadioButton3", x, y + 30, cx, cy, "RB Test 3" x = 55 y = 10 wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "myRadioButton4", x, y, cx, cy, "RB Test 4" wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "myRadioButton5", x, y + 15, cx, cy, "RB Test 5" wsFactory.CreateWidget WS_RADIO_BUTTON, 0, "myRadioButton6", x, y + 30, cx, cy, "RB Test 6" x = 15 y = 55 cx = 45 wsFactory.CreateWidget WS_LABEL, 0, "groupDisplayLabel", x, y, cx, 5, "Group display" wsFactory.CreateWidget WS_LABEL, 0, "group1State", x, y + 5, cx, 5, "" wsFactory.CreateWidget WS_LABEL, 0, "group2State", x, y + 10, cx, 5, "" wsFactory.CreateWidget WS_LABEL, 0, "group3State", x, y + 15, cx, 5, "" 'Fonts wsFactory.CreateCustomFont 1, 14, True, False, False, "Times New Roman", WS_CENTER wsFactory.CreateCustomFont 4, 16, False, False, True, "Times New Roman", WS_LEFT wsFactory.CreateCustomFont 5, 15, True, False, False, "Tahoma", WS_CENTER wsFactory.LoadExternalIcon 3, WS_EXIT, "iconlib.dll" wsFactory.LoadExternalIcon 4, WS_RELOAD, "iconlib.dll" wsWidget.SetIconByName "exitButton", 3 wsWidget.SetIconByName "clearButton", 4 wsForm.AddObjectByName "myForm", "formTittle" wsForm.AddObjectByName "myForm", "exitButton" wsForm.AddObjectByName "myForm", "clearButton" wsForm.AddObjectByName "myForm", "myRadioButton" wsForm.AddObjectByName "myForm", "myRadioButton4" wsForm.AddObjectByName "myForm", "myRadioButton2" wsForm.AddObjectByName "myForm", "myRadioButton5" wsForm.AddObjectByName "myForm", "myRadioButton3" wsForm.AddObjectByName "myForm", "myRadioButton6" wsForm.AddObjectByName "myForm", "group1State" wsForm.AddObjectByName "myForm", "group2State" wsForm.AddObjectByName "myForm", "group3State" wsForm.AddObjectByName "myForm", "groupDisplayLabel" wsWidget.SetFontByName "formTittle", 1 wsWidget.SetFontByName "exitButton", 1 wsWidget.ModifyStyleByName "myRadioButton4", WS_STYLE_PUSH_LIKE wsWidget.ModifyStyleByName "myRadioButton5", WS_STYLE_PUSH_LIKE wsWidget.ModifyStyleByName "myRadioButton6", WS_STYLE_PUSH_LIKE 'Two radio button groups are defined wsWidget.SetGroupIdByName "myRadioButton", 1 wsWidget.SetGroupIdByName "myRadioButton2", 1 wsWidget.SetGroupIdByName "myRadioButton3", 1 InitRBGroup1 ("myRadioButton") InitRBGroup1 ("myRadioButton2") InitRBGroup1 ("myRadioButton3") wsWidget.SetGroupIdByName "myRadioButton4", 2 wsWidget.SetGroupIdByName "myRadioButton5", 2 wsWidget.SetGroupIdByName "myRadioButton6", 2 InitRBGroup2 ("myRadioButton4") InitRBGroup2 ("myRadioButton5") InitRBGroup2 ("myRadioButton6") wsWidget.SetStateByName "myRadioButton4", WS_STATE_CHECKED bResult = wsForm.ShowByName("myForm", True, True) 'Shows initial state of the groups sState = wsWidget.GetStateByName("myRadioButton") sCurrentState = "RBtn: " + sState sState = wsWidget.GetStateByName("myRadioButton4") sCurrentState = sCurrentState + " " + "RBtn4: " + sState wsWidget.SetTextByName "group1State", sCurrentState sState = wsWidget.GetStateByName("myRadioButton2") sCurrentState = "RBtn2: " + sState sState = wsWidget.GetStateByName("myRadioButton5") sCurrentState = sCurrentState + " " + "RBtn5: " + sState wsWidget.SetTextByName "group2State", sCurrentState sState = wsWidget.GetStateByName("myRadioButton3") sCurrentState = "RBtn3: " + sState sState = wsWidget.GetStateByName("myRadioButton6") sCurrentState = sCurrentState + " " + "RBtn6: " + sState wsWidget.SetTextByName "group3State", sCurrentState bResult = True While (bEnd = False And bResult) bResult = wsForm.GetEvent() sObjectName = wsForm.GetLastEventSourceName() If sObjectName = "clearButton" Then bResult = wsForm.RestoreInitialState() End If sState = wsWidget.GetStateByName("myRadioButton") sCurrentState = "RBtn: " + sState sState = wsWidget.GetStateByName("myRadioButton4") sCurrentState = sCurrentState + " " + "RBtn4: " + sState wsWidget.SetTextByName "group1State", sCurrentState sState = wsWidget.GetStateByName("myRadioButton2") sCurrentState = "RBtn2: " + sState sState = wsWidget.GetStateByName("myRadioButton5") sCurrentState = sCurrentState + " " + "RBtn5: " + sState wsWidget.SetTextByName "group2State", sCurrentState sState = wsWidget.GetStateByName("myRadioButton3") sCurrentState = "RBtn3: " + sState sState = wsWidget.GetStateByName("myRadioButton6") sCurrentState = sCurrentState + " " + "RBtn6: " + sState wsWidget.SetTextByName "group3State", sCurrentState If sObjectName = "exitButton" Or sObjectName = "WSFunctionKeysController" Then bEnd = True End If Wend End Sub Public Function InitRBGroup1(sButtonName As String) wsWidget.SetFontByName sButtonName, 4 wsWidget.SetTextColorByName sButtonName, 240, 244, 244 wsWidget.SetBackGroundColorByName sButtonName, 78, 187, 89 End Function Public Function InitRBGroup2(sButtonName As String) wsWidget.SetBackGroundColorByName sButtonName, 143, 237, 171 wsWidget.SetTextColorByName sButtonName, 9, 169, 79 wsWidget.SetFontByName sButtonName, 5 End Function