Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:1k
源码类别:

VC书籍

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TForm1 *Form1;
  9. //---------------------------------------------------------------------------
  10. __fastcall TForm1::TForm1(TComponent* Owner)
  11.         : TForm(Owner)
  12. {
  13. }
  14. //---------------------------------------------------------------------------
  15. void __fastcall TForm1::Button1Click(TObject *Sender)
  16. {
  17.   int nn;
  18.   AnsiString ss;
  19.   nn=ListBox1->ItemIndex;
  20.   if(nn<1)return;
  21.   ss=ListBox1->Items->Strings[nn];
  22.   ListBox1->Items->Strings[nn]=
  23.     ListBox1->Items->Strings[nn-1];
  24.   ListBox1->Items->Strings[nn-1]=ss;
  25.   ListBox1->ItemIndex=nn-1;
  26. }
  27. //---------------------------------------------------------------------------
  28. void __fastcall TForm1::Button2Click(TObject *Sender)
  29. {
  30.   int nn;
  31.   AnsiString ss;
  32.   nn=ListBox1->ItemIndex;
  33.   if((nn<0)||(nn>=(ListBox1->Items->Count-1)))return;
  34.   ss=ListBox1->Items->Strings[nn];
  35.   ListBox1->Items->Strings[nn]=
  36.     ListBox1->Items->Strings[nn+1];
  37.   ListBox1->Items->Strings[nn+1]=ss;
  38.   ListBox1->ItemIndex=nn+1;
  39. }
  40. //---------------------------------------------------------------------------