⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.cpp

📁 一个自助聊天服务程序
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CSPIN"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormShow(TObject *Sender)
{
   this->RadioGroup1->Items->LoadFromFile("items.txt");
   Index=-1;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::RadioGroup1Click(TObject *Sender)
{

//   this->RadioGroup1->Items->Strings
   if(Index>=0) this->ListBox1->Items->SaveToFile(this->RadioGroup1->Items->Strings[Index]+".txt");


   if (FileExists(this->RadioGroup1->Items->Strings[this->RadioGroup1->ItemIndex]+".txt"))
    {
   this->ListBox1->Items->LoadFromFile(this->RadioGroup1->Items->Strings[this->RadioGroup1->ItemIndex]+".txt");
   }else  this->ListBox1->Items->Clear();
   Index=this->RadioGroup1->ItemIndex;

}
//---------------------------------------------------------------------------

void __fastcall TForm1::ListBox1Click(TObject *Sender)
{
   this->Memo1->Lines->Clear();
   this->Memo1->Lines->Add(this->ListBox1->Items->Strings[this->ListBox1->ItemIndex]);
   this->Memo1->SelectAll();
   this->Memo1->CopyToClipboard();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1KeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
    if(Key==13)
    {
         if(RadioGroup2->ItemIndex==0){
            RadioGroup1->Items->Add(Edit1->Text);
            RadioGroup1->Items->SaveToFile("items.txt");
         };
         if(RadioGroup2->ItemIndex==1){
            ListBox1->Items->Add(Edit1->Text);
      //      ListBox1->Items->SaveToFile(this->RadioGroup1->Items->Strings[this->RadioGroup1->ItemIndex]+".txt");
         };
      Edit1->Text="";
    };
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
   if(RadioGroup2->ItemIndex==0){
            RadioGroup1->Items->Add(Edit1->Text);
            RadioGroup1->Items->SaveToFile("items.txt");
         };
         if(RadioGroup2->ItemIndex==1){
            ListBox1->Items->Add(Edit1->Text);
     //       ListBox1->Items->SaveToFile(this->RadioGroup1->Items->Strings[this->RadioGroup1->ItemIndex]+".txt");
         };
         Edit1->Text="";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox1DblClick(TObject *Sender)
{   this->ListBox1->Items->Delete(this->ListBox1->ItemIndex);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N1Click(TObject *Sender)
{
   if(OpenDialog1->Execute())
   {
     this->ListBox2->Items->LoadFromFile(OpenDialog1->FileName);
   };

}
//---------------------------------------------------------------------------
void __fastcall TForm1::N4Click(TObject *Sender)
{
    this->N4->Checked=!this->N4->Checked;
     this->N1->Enabled=this->N4->Checked;
    this->ListBox1->Visible=!this->N4->Checked;
    this->ListBox2->Visible=this->N4->Checked;

}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox2MouseUp(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
    if(this->ListBox2->ItemIndex==-1) return;
    if(Button==mbRight)
    {
       ListBox1->Items->Add(this->ListBox2->Items->Strings[this->ListBox2->ItemIndex]);
//       ListBox1->Items->SaveToFile(this->RadioGroup1->Items->Strings[this->RadioGroup1->ItemIndex]+".txt");
        this->ListBox2->Items->Delete(this->ListBox2->ItemIndex);
    };

}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListBox2DblClick(TObject *Sender)
{
    this->ListBox1->Items->Delete(this->ListBox1->ItemIndex);
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -