Ecere SDK/eC Forums
http://www.ecere.com/forums/
Print view

动态添加按钮 add a button Dynamically
http://www.ecere.com/forums/viewtopic.php?f=30&t=35
Page 1 of 1
Author:  liqi98136 [ Wed Mar 10, 2010 7:51 am ]
Post subject:  动态添加按钮 add a button Dynamically

Code: Select all

import "ecere"

class Form1 : Window
{
   text = "增加删除按钮add&delete button";
   background = activeBorder;
   borderStyle = sizable;
   hasMaximize = true;
   hasMinimize = true;
   hasClose = true;
   size = { 200, 240 };
   anchor = { horz = -215, vert = -108 };

   Button button1
   {
      this, text = "创建new", position = { 40, 48 };

      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
         if(newbutton)
         {
            MessageBox{text="提示info",contents="你已经增加了新的按钮!"}.Modal();
         }
         else
         {
            newbutton = Button{ 
            this,position ={button1.position.x,button1.position.y+100 },text = "新增的按钮" ;
            
            bool NotifyClicked(Button button, int x, int y, Modifiers mods)
            {
              MessageBox{text="提示info",contents="您选中的是动态增加的按钮!"}.Modal(); 
            }
            };
            newbutton.Create();

         }
         return true;
      }
   };
   Button button2
   {
      this, text = "删除delete", position = { 96, 48 };

      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
         if(newbutton)
         {
            newbutton.Destroy(0);
            newbutton = null;
         }
         else
         {
           MessageBox{text="提示info",contents="没有增加新的按钮!"}.Modal(); 
         }
         return true;
      }
   };

   private Button newbutton;
}

Form1 form1 {};
All times are UTC-05:00 Page 1 of 1