[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Get events from controls created by code.
[Thread Prev] | [Thread Next]
- Subject: Re: Get events from controls created by code.
- From: T Lee Davidson <t.lee.davidson@xxxxxxxxx>
- Date: Fri, 3 Jan 2025 12:02:16 -0500
- To: user@xxxxxxxxxxxxxxxxxxxxxx
On 1/3/25 05:39, System64 Development wrote:
Hi,When controls are created in a module, not on the form, but then these are placed in a panel on the main form, what is the way to get the events on these controls on the form?This example print the text when Textarea1 change but not when the code created TextArea change. 'FMain Public Sub Button1_Click() Makecontrols(Panel1) End Public Sub Makecontrols(cn As Container) Dim ob As Panel ob = Auxiliary.Capsule(Panel1) End Public Sub Text_Change() Dim o As Object o = Last Print o.Text End Public Sub TextArea1_Change() Dim o As Object o = Last Print o.Text End
[snip]Despite the fact that the child Panel created in the Auxiliary module, is given FMain.Panel1 as its parent, the default event observer for that child Panel is the Auxiliary module itself (and as far as I know, that cannot be changed). If you move the Text_Change event handler to the module, the event will be handled.
If you want the event to *also* be handled in FMain, then you will need to attach an Observer to it in FMain: https://gambaswiki.org/wiki/comp/gb/observerThere may be better ways of doing this as it may not be practical for many controls, but here is a quick example with a modified Makecontrols procedure (with "Public TextObserver As Observer" at the top of FMain):
[code] Public Sub Makecontrols(cn As Container) Dim ob As Panel ob = Auxiliary.Capsule(Panel1) For Each ctrl As Control In ob.Children If ctrl.Name = "Text" Then TextObserver = New Observer(ctrl) As "Text" Next End [/code] -- Lee --- Gambas User List Netiquette [https://gambaswiki.org/wiki/doc/netiquette] ---- --- Gambas User List Archive [https://lists.gambas-basic.org/archive/user] ----
Re: Get events from controls created by code. | System64 Development <64xcode@xxxxxxxxx> |
Get events from controls created by code. | System64 Development <64xcode@xxxxxxxxx> |