listbox control and button

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

listbox control and button

Post by liqi98136 »

listbox 学习实例

Code: Select all

import "ecere"
 
class Friends : struct
{ 
    public:
     char * name; 
     char * job; 
     int age; 
 
};
Array<Friends> friends  
{ 
    [{"Erika", "waitress", 18}, 
     {"Thomas", "programmer", 25}, 
     {"George", "police officer", 26}, 
     {"Michael", "producer", 38}, 
     {"Jane", "steward", 28} ]
}; 
 
 
class Form1 : Window
{
   text = "Form1";
   background = activeBorder;
   borderStyle = sizable;
   hasMaximize = true;
   hasMinimize = true;
   hasClose = true;
   size = { 576, 432 };
   anchor = { horz = -11, vert = 4 };
 
   bool bfirst, blast;
 
[color=#400080]   DataField nameField { dataType = class(String), width = 50,header = "Name",editable = true  };
   DataField jobField { dataType = class(String), width = 80 ,header = "Job",editable = true };
   DataField ageField { dataType = class(int),  header = "Age",editable = true };[/color]
 
   Form1()
  {
         DataRow row;
         Iterator<Friends> i { friends };
         int j=0;
 
         bfirst=true;
         blast=true; 
 
[color=#0000FF]         listBox1.AddField(nameField);
         listBox1.AddField(jobField);
         listBox1.AddField(ageField);[/color]
 
 
        for(i:friends)        
         {
 
[color=#004000]            row = listBox1.AddRow();
            row.tag = j;
            row.SetData(nameField, i.name);
            row.SetData(jobField, i.job);
            row.SetData(ageField, i.age);[/color]
            j++;
 
         }
 
 
  }
   Label label4 { this, text = "Information", inactive = false, font = { "Tahoma", 20 }, size = { 516, 149 }, position = { 40, 192 }, isGroupBox = true };
   Button button1 
   {      
      this, text = "FIRST", position = { 160, 360 };
 
      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
[color=#0000FF]         listBox1.SelectRow(listBox1.firstRow);
         listBox1.Activate();[/color]
 
         bfirst=true;
         blast =false;
         Update(null);
         return true;
      }
   };
   Button button2 
   {      
      this, text = "PREV", position = { 216, 360 };
 
      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
 
[color=#0000FF]         if(!listBox1.currentRow || listBox1.currentRow.previous)
            listBox1.SelectRow(listBox1.currentRow ? listBox1.currentRow.previous : listBox1.lastRow);
                   [/color]
         listBox1.Activate();
         blast=false;
         if(!listBox1.currentRow.previous)
            bfirst = true;
         Update(null);
         return true;
      }
   };
   Button button3 
   {
      this, text = "NEXT", position = { 272, 360 };
 
      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
[color=#0000BF]         if(!listBox1.currentRow || listBox1.currentRow.next)
            listBox1.SelectRow(listBox1.currentRow ? listBox1.currentRow.next : listBox1.firstRow);
    [/color]
         listBox1.Activate();
         bfirst=false;
         if(! listBox1.currentRow.next)
            blast=true;
         Update(null);
         return true;
      }
 
 
   };
   Button button4 
   {      
      this, text = "LAST", position = { 328, 360 };
 
      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
[color=#0000FF]         listBox1.SelectRow(listBox1.lastRow);[/color]
         listBox1.Activate();
 
         blast=true;
         bfirst=false;
 
         Update(null);
         return true;
      }
   };
   Button button5 
   {      
      this, text = "EXIT", position = { 496, 360 };
 
      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
         if(MessageBox{type=okCancel,text="exit",contents="Are you sure to quit?"}.Modal()==ok)
            Destroy(0);
         return true;
      }
   };
   Label label1 { label4, this, "NAME:", size = { 278, 33 }, position = { 48, 32 } };
   Label label2 { label4, this, "JOB:", size = { 302, 33 }, position = { 48, 72 } };
   Label label3 { label4, this, "AGE:", size = { 318, 33 }, position = { 48, 104 } };
   ListBox listBox1 
   {
      this, size = { 500, 132 }, position = { 40, 40 }, moveRows = true, true, true, hasHeader = true, sortable = true;
 
      bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
      {
         Friends temp{};
         [color=#0000FF]temp.name=listBox.currentRow.GetData(nameField);
         temp.job=listBox.currentRow.GetData(jobField);
         temp.age=listBox.currentRow.GetData(ageField);[/color]         
         label1.SetText("NAME:%s",temp.name);
         label2.SetText("JOB:%s",temp.job);
         label3.SetText("AGE:%d",temp.age);
         Update(null);
         delete temp;
         return true;
      }
 
   };
 
   void OnRedraw(Surface surface)
   {
       button2.disabled =bfirst;  
       button3.disabled =blast;  
   }
}
 
Form1 form1 {};
 
感谢Jerome :D
Post Reply