VBAndCs / sVB-Small-Visual-Basic

Small Visual Basic (sVB) is an educational programming language, created by Eng. Mohammad Hamdy as an evolved version of Microsoft Small Basic (SB). It is meant to be easier and more powerful at the same time, to introduce programming basics to kids and beginners of any age, provided that they can use the English keyboard on the Windows OS.
Other
232 stars 16 forks source link

The checked state of the ToggleButton in the OnClick event conflicts with that in the OnCheck event. #39

Closed dynamicboy closed 3 months ago

dynamicboy commented 9 months ago

Version: 2.8.7.5 Details: Step1: Drag a togglebutton from toolbox to form. Step2: In Form Code,input code as below:

ToggleButton1.OnClick = LookCheckedState

Sub LookCheckedState
    TW.WriteLine(ToggleButton1.Checked)
EndSub

Step3: Click Run Step4: Click the togglebutton. Result: it output "False", but it should be "True", because the button stays down. 2023-12-30_145508

Step5: change form code as below (change OnClick to OnCheck):

ToggleButton1.OnCheck = LookCheckedState

Sub LookCheckedState
   TW.WriteLine(ToggleButton1.Checked)
EndSub

Step6: Click Run, then Click togglebutton Result: it output "True", which is correct, because the button stays down. 2023-12-30_145706

VBAndCs commented 9 months ago

Hi @dynamicboy,

Thanks for reporting this.

sVB forms and controls are actually WPF controls, but for simplicity I make them look like windows forms controls. WPF is powerful but has some issues. for example, there is no Click event for controls except button based controls like Button and ToggleButton. So, to generalize a click event for the form and controls, I used the MouseLeftBiuttonUp event, and because some controls suppresses this event, I used the PreviewMouseLeftBiuttonUp event which actually occurs before the controls responds to the mouse click. This is why the state of the Checked event is different between the OnClick and OnCheck events.

I made some changes to handle the button-based control Click event directly, so, in the upcoming sVB 2.8.8 version this isuue will be solved.

Thanks


From: dynamicboy @.> Sent: Saturday, December 30, 2023 7:00 AM To: VBAndCs/sVB-Small-Visual-Basic @.> Cc: Subscribed @.***> Subject: [VBAndCs/sVB-Small-Visual-Basic] The checked state of the ToggleButton in the OnClick event conflicts with that in the OnCheck event. (Issue #39)

Version: 2.8.7.5 Details: Step1: Drag a togglebutton from toolbox to form. Step2: In Form Code,input code as below:

ToggleButton1.OnClick = LookCheckedState

Sub LookCheckedState TW.WriteLine(ToggleButton1.Checked) EndSub

Step3: Click Run Step4: Click the togglebutton. Result: it output "False", but it should be "True", because the button stays down. 2023-12-30_145508.png (view on web)https://github.com/VBAndCs/sVB-Small-Visual-Basic/assets/7421525/fc7d574a-7530-42ba-a5a0-9d40b646edf0

Step5: change form code as below (change OnClick to OnCheck):

ToggleButton1.OnCheck = LookCheckedState

Sub LookCheckedState TW.WriteLine(ToggleButton1.Checked) EndSub

Step6: Click Run, then Click togglebutton Result: it output "True", which is correct, because the button stays down. 2023-12-30_145706.png (view on web)https://github.com/VBAndCs/sVB-Small-Visual-Basic/assets/7421525/afd890ee-3a93-4700-85e6-584e41323803

— Reply to this email directly, view it on GitHubhttps://github.com/VBAndCs/sVB-Small-Visual-Basic/issues/39, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALQ5MVTLJXESDYSEMWJ5N2TYL632JAVCNFSM6AAAAABBHKOGDGVHI2DSMVQWIX3LMV43ASLTON2WKOZSGA3DANRVHEZDSMY. You are receiving this because you are subscribed to this thread.Message ID: @.***>