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
222 stars 16 forks source link

AllowTransparent in form disigner may block OnKeyDown Event #38

Closed dynamicboy closed 1 month ago

dynamicboy commented 6 months ago

Version: 2.8.7.5 Details: Step1: check “AllowTransparent” in context menu of mouse right button in form designer, 2023-12-29_235003

Step2: In Form Code, input code as below:

Me.OnKeyDown = Exit
Sub Exit
    Me.Close()
EndSub

Step3: Click Run Step4: Click the form displayed. Step5: Press any key on keyboard Result: The form will not close,but it should be closed according to the code.

BTW, if use code to call Me.AllowTransparency() instead, press any key could close the form.

VBAndCs commented 6 months ago

Hi @dynamicboy, Thanks for reporting this. I draw controls on a canvas on the form, and when the form is transparent, the canvas handles the events like the OnKeyDown. I found that I wrote an if statement that cancels the handler when event source (the canvas) is not the event sender (the form), so I corrected this condition to treat the canvas and the form equally, and the code now works. This fix will be available in sVB v2.8.8, which will come soon when I complete the properties window I am adding to the form designer.

Note that you don't need to use:


Me.OnKeyDown = Exit

Sub Exit

    Me.Close()

EndSub

You can just use the event handler naming convention:


Sub Form1_ OnKeyDown

    Me.Close()

EndSub

And the code editor can generate this handler for you by choosing the form name from the upper left list, and choose the OnKeyDown from the upper right list.

Thanks.


From: dynamicboy @.> Sent: Friday, December 29, 2023 4:28 PM To: VBAndCs/sVB-Small-Visual-Basic @.> Cc: Subscribed @.***> Subject: [VBAndCs/sVB-Small-Visual-Basic] AllowTransparent in form disigner may block OnKeyDown Event (Issue #38)

Version: 2.8.7.5 Details: Step1: check “AllowTransparent” in context menu of mouse right button in form designer, 2023-12-29_235003.png (view on web)https://github.com/VBAndCs/sVB-Small-Visual-Basic/assets/7421525/e4dfb64b-84e8-4fbd-90c3-6eebfa4f6bdb

Step2: In Form Code, input code as below:

Me.OnKeyDown = Exit Sub Exit Me.Close() EndSub

Step3: Click Run Step4: Click the form displayed. Step5: Press any key on keyboard Result: The form will not close,but it should be closed according to the code.

BTW, if use code to call Me.AllowTransparency(), press any key could close the form.

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

[https://s-install.avcdn.net/ipm/preview/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Virus-free.www.avast.comhttps://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail

VBAndCs commented 6 months ago

By the way, calling AllowTransparency in code will not really allow the form to be transparent! This is a quote from the sVB reference book:

You must do this before the form is displayed, which is valid only when you create the form by calling the Forms.AddForm or Forms.LoadForm methods, and before you call the Form.Show method. Forms created by the form designer will not be affected by calling the AllowTransparency method, because the form is displayed before executing any code you write in the global area of the form. In such case, you must use the form designer to allow form transparency, by right-clicking the form surface and checking the "Allow Transparency" context menu item. This will add a call to the Form.AllowTransparency method in the code behind generated in the form.sb.gen file, before calling the Form.Show method.

The "Form Shape" project in the sVB samples folder shows you an interesting example on the AllowTransparency method, and you can see the details about this project in the Form.AllowTransparency section this in the reference book.


From: dynamicboy @.> Sent: Friday, December 29, 2023 4:28 PM To: VBAndCs/sVB-Small-Visual-Basic @.> Cc: Subscribed @.***> Subject: [VBAndCs/sVB-Small-Visual-Basic] AllowTransparent in form disigner may block OnKeyDown Event (Issue #38)

Version: 2.8.7.5 Details: Step1: check “AllowTransparent” in context menu of mouse right button in form designer, 2023-12-29_235003.png (view on web)https://github.com/VBAndCs/sVB-Small-Visual-Basic/assets/7421525/e4dfb64b-84e8-4fbd-90c3-6eebfa4f6bdb

Step2: In Form Code, input code as below:

Me.OnKeyDown = Exit Sub Exit Me.Close() EndSub

Step3: Click Run Step4: Click the form displayed. Step5: Press any key on keyboard Result: The form will not close,but it should be closed according to the code.

BTW, if use code to call Me.AllowTransparency(), press any key could close the form.

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