Page 1 of 1

Code snippets 1: ListBox

PostPosted: Mon Aug 22, 2011 3:51 am
by samsam598
Code: Select all
import "ecere"
 
class Form1 : Window
{
   text = "Form1";
   background = activeBorder;
   borderStyle = fixed;
   hasClose = true;
   size = { 688, 256 };
   anchor = { horz = -43, vert = -93 };
 
   Label label1 { this, text = "在左边的ListBox双击一行则将该行文字添加给右边的ListBox", font = { "Tahoma", 9 }, size = { 324, 21 }, position = { 16, 8 } };
   Label label2 { this, text = "在右边的ListBox里双击一行则将该行删除", font = { "Tahoma", 9 }, size = { 308, 21 }, position = { 352, 8 } };
   ListBox listBox2
   {
      this, text = "listBox2", size = { 316, 172 }, position = { 352, 40 };
 
      bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
      {
         if(listBox.currentRow)
            listBox.DeleteRow(listBox.currentRow);
         return true;
      }
   };
   ListBox listBox1
   {
      this, text = "listBox1", size = { 324, 172 }, position = { 16, 40 };
 
      bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
      {
         if( listBox.currentRow)
            listBox2.AddString(listBox.currentRow.string);
         return true;
      }
   };
 
   bool OnPostCreate(void)
   {
      int i;
      for(i=0;i<10;i++)
      {
         this.listBox1.AddStringf("Line #%d",i+1);
         this.listBox1.AddStringf("第%d行",i+1);
      }
      return true;
   }
}
 
Form1 form1 {};
 
 

Re: Code snippets 1: ListBox

PostPosted: Wed Aug 24, 2011 7:43 am
by liqi98136
顶一个,加油.

Re: Code snippets 1: ListBox

PostPosted: Thu Sep 08, 2011 1:28 am
by D.Bane
Hi Sam.

Hope you do not mind me saying this but you will have less to write in your code...

Code: Select all
 
ListBox listBox2
 {
    this, text = "listBox2", size = { 316, 172 }, position = { 352, 40 };
 
    bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
    {
       //the call is made inside of the listBox2 and it is referenced here as listBox
       if(listBox.currentRow)
          listBox.DeleteRow(listBox.currentRow);
       return true;
    }
 };
 ListBox listBox1
 {
    this, text = "listBox1", size = { 324, 172 }, position = { 16, 40 };
 
    bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
    {
       //the call is made inside of the listBox1 and it is referenced here as listBox as well
       // we need to call the listBox2 as it is
       if( listBox.currentRow)
          listBox2.AddString(listBox.currentRow.string);
       return true;
    }
 };


You also do not need to write the "this." part as it will call it just like it is not there... This all of course is not going to generate errors, but it is faster :)

Best Regards, oh, and thank you for the questions on forum, you saved me some trouble :)
D.Bane.

Re: Code snippets 1: ListBox

PostPosted: Thu Sep 08, 2011 4:28 am
by samsam598
Hi D.Bane,

Thank you!Yes,just noticed that
Code: Select all
bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)

it can be referenced as listBox.

Also noted that in many cases the this can be omitted.I used it just to fire the code auto-completion :D

Appreciate your help and you are always welcome.

Regards,
Sam

Re: Code snippets 1: ListBox

PostPosted: Thu Sep 08, 2011 8:31 am
by jerome
Thanks Sam and D.Bane for the samples =)

D.Bane is right the 'listBox' parameter is passed in for convenience, and you can use it instead of 'listBox1' or 'this.listBox1' but the main reason for it is so that you can use the same method for multiple controls, e.g.
Code: Select all
listBox1.NotifyClicked = AnyListBoxClicked;
listBox2.NotifyClicked = AnyListBoxClicked;

(You can experiment with the Methods Sheet's detach and attach buttons)

Then you know which list box sent the notification :D
But it's fine as well to use 'listBox1' (which translates to this.listBox1) if you want to be explicit.

Sam, you can bring up the auto-complete with Ctrl-Space, which lists all identifiers available in the current context, and if you have started typing anything it will auto-complete it. Ctrl-Shift-Space is to bring up the instantiation members and function parameters. The auto-complete is a bit buggy right now, it will be part of the focus of 0.44 pre-release 2 to fix most of the bugs.

Our milestones ahead: https://launchpad.net/ecere/+milestones

Re: Code snippets 1: ListBox

PostPosted: Thu Sep 22, 2011 9:08 pm
by linghutf
控件库里没有?基本控件应该学学Qt,都做出来。