Autore Topic: Come ritornare un evento da un Form secondario inglobato ?  (Letto 277 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.311
  • Ne mors quidem nos iunget
    • Mostra profilo
Riporto dalla M.L.I. questa discussione:


" I need to return a button click from an embedded sub form. I managed to
get the sub form embedded in the main form using the code found in the
tips that run when Gambas loads.

The sub form has a button called OK. I want to capture the btnOK_Click
event and use it in the main form. I know I can use a global variable
that can be seen by both forms but, I'd like to use another method. I've
been trying Object.Attach as suggested by Benoit in an email I found on
the net. I've not been able to get that working.

Would you help me with the syntax of Object.Attach or suggest a better
approach? I am still learning Gambas syntax so please do not assume
anything when sending code examples.

Thanks,
Marty
"


" Make your Button on the embedded Form public in the form editor in the IDE.
Let the Button be btnOK and an instance of your embedded Form be
"hEmbedded". Then you can do the following in FMain:


Codice: gambas [Seleziona]
Object.Attach(hEmbedded.btnOK, Me, "btnOK")


This will attach the Button btnOK on the embedded Form to FMain. The Button
gets "btnOK" as its event name and will then raise btnOK_Click() in FMain.

Regards,
Tobi
"


" never use public control
insteed in the embedded form add

Codice: gambas [Seleziona]
Public Function GetButton() as Button
  return btnOk
end

Fabien Bodard "


" > never use public control

Why?

Tobi
"


" It's a bad programming use... and gambas was not drawn for that. The
correct and more efficient way is the one i say..

The ide for exemple have no one public ctl.

Fabien Bodard
"
« Ultima modifica: 27 Agosto 2013, 13:35:01 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »