[Closed] dotnet Event using a Struct Function
Hi,
I read some all topics talking about dotnet events and structs that i could find, but I gave up trying to figure out what is wrong with this:
struct testStruct
(
form = dotnetobject "form",
bt = dotnetobject "button",
fn fntest =
(
print "fntest"
),
start = (
form.controls.add bt
form.show()
)
)
test = testStruct()
dotnet.addEventHandler test.bt "click" test.fntest
When you click the button, the function doesn’t work but if you run the test.test1() you’ll see that the function works.
I know that I could make it work declaring the function outside the struct or declaring the the event handler inside the struct “start” like this:
dotnet.addEventHandler bt "click" fntest
But can anyone explain why it is not working when I try to add a event handler outside the struct? Or if there is a way to make it work similar to this example?
Thanks for your attention.
Every thing should be in the struct. Create a function that builds the form, button adds the event handler and launches the form. Then event handler for the button should be directly in the struct as well but if it needs to call other functions in the struct you will have to access the struct via an instance of the struct.
struct test
(
fn eventHander sender arg=
(
print sender
),
fn makeForm=
(
--make form here
),
run=makeForm()
)
test=test()
Hi thanks for the reply,
So there is no way to add an event handler outside the struct using the struct function?
Hey pen thanks for your comment.
So there is no way to add an event handler with a struct function outside the struct?
Currently I’m using the struct like you said, but I was just curious to know if there is a way to make it works outside the struct.