Your prova2.h and main.cpp modified.
The addition will be automatically done each time x or y is updated.
prova2.h :
#ifndef _prova2_prova2_h
#define _prova2_prova2_h
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
#define LAYOUTFILE <prova2/prova2.lay>
#include <CtrlCore/lay.h>
class prova2 : public Withprova2Layout<TopWindow> {
public:
typedef prova2 CLASSNAME;
prova2();
private:
void calcolo();
};
#endif
And main.cpp :
#include "prova2.h"
prova2::prova2()
{
CtrlLayout(*this, "Window title");
// you must add a callback on x or y fields update
x <<= THISBACK( calcolo) ;
y <<= THISBACK( calcolo) ;
}
void prova2::calcolo()
{
// You do the addition only if x and y are valid
if( !( x.IsNullInstance() || y.IsNullInstance() ) )
{
// Here, you must get the value inserted in your x EditInt field (done with ~x)
int xValue = ~x ;
// And, you must also get the value inserted in your y EditInt field (done with ~y)
int yValue = ~y ;
// And now, you must update your somma Label field with the addition.
// As somma is a Label, we must convert your result into text (done by Format)
// and then, you update your field by the SetText method.
somma.SetText( Format( "%d", xValue+yValue ) );
}
else
{
somma.SetText( "" ) ;
}
return ;
}
GUI_APP_MAIN
{
prova2().Run();
}