Code Snippet04-Share data between forms(Wizard style)

General help with the Ecere Cross Platform GUI toolkit: Window, common controls, events, etc.
Help with the 2D Graphics library: Surface, Display, Bitmap, Font and others.
Post Reply
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

Code Snippet04-Share data between forms(Wizard style)

Post by samsam598 »

Purpose:Sharing variable between two forms.Pass a value to a variable (property version of Form 1 here)belongs to form1 and change its value in Form2.The caption of form1 and the text of label in form2 will indicate this change.A very simple wizard based application.
form1.ec

Code: Select all

 
import "ecere"
import "form2"
class Form1 : Window
{
   text = "Form1";
   background = activeBorder;
   borderStyle = fixed;
   hasMinimize = true;
   hasClose = true;
   size = { 488, 192 };
   anchor = { horz = -31, vert = -133 };
   nativeDecorations = true;
 
   Button button1 
   {
      this, text = "(N)ext", altN, position = { 416, 128 };
 
      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
         Form2 form2{};
         form2.Create();
 
 
         visible=false;
         return true;
      }
   };
   Picture picture1 { this, text = "picture1", anchor = { left = 16, top = 16, right = 16, bottom = 52 }, image = { "C:\\person\\ecere\\ecere\\ide\\res\\ecereBack.jpg" } };
 
   float version;
   public:
   property float version
   {
      set{version=value;}
      get{return version;}
   }
 
   char versionStr[32];
   property char* versionStr
  {
     get
     {
        char result[32];
        sprintf(result,"%.1f",version);
        strcpy(versionStr,result);
        return versionStr;
     }
  }
 
   void OnRedraw(Surface surface)
   {
     char caption[40];
     sprintf(caption,"MultiformApp-V%.1f",this.version);
     this.text=caption; 
 
   }
}
 
Form1 form1 {  version=1.0f;  };
 
form2.ec

Code: Select all

 
 
import "ecere"
import "form1"
 
class Form2 : Window
{
   text = "Form2";
   background = activeBorder;
   borderStyle = fixed;
   hasMinimize = true;
   hasClose = true;
   size = { 520, 152 };
   anchor = { horz = -28, vert = -140 };
   nativeDecorations = true;
 
   Button btnBack 
   {
      this, text = "(B)ack", altB, position = { 424, 72 };
 
      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
 
         form1.visible=true; 
 
         Destroy(0);  
         return true;
      }
   };
   master=form1;
 
   bool OnClose(bool parentClosing)
   {
 
 
      form1.visible=true;  
 
      Destroy(0); 
      return true;
   }
   Label label1 { this, text = "label1", foreground = seaGreen, font = { "Tahoma", 16, bold = true, italic = true }, size = { 476, 45 }, position = { 16, 16 } };
 
   bool OnPostCreate(void)
   {
 
      char str[40];
      form1.version=form1.version+0.1f;
      sprintf(str,"The latest version of form1 is %.1f",form1.version);
 
      this.label1.text=str;
      return true;
   }
}
 
Post Reply