动态添加按钮 add a button Dynamically

来自中国的朋友,欢迎您在本版面使用中文讨论问题。请注意,如果您想得到不懂中文的人的帮助,请同时提供英文译文。
Help and discussions in Chinese.
Post Reply
liqi98136
Posts: 53
Joined: Sun Jan 17, 2010 11:37 pm

动态添加按钮 add a button Dynamically

Post by liqi98136 »

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 {};
Post Reply