Kontaktlarni saqlovchi soda dastur uchun ikta forma oynasidan foydalandik
Download 53.06 Kb.
|
Raxmatillo toirov 2-dedline
Kontaktlar Kontaktlarni saqlovchi soda dastur uchun ikta forma oynasidan foydalandik. Birinchi forma: Korinishida boladi. Bu yerda ikta panel qidiruv qismi va past qismida turgan boshqaruv qismiga qo’yilgan. Orta qismoga esa listbox komponentasi qollangan. Qidiruv qismida bita Edit va bita StarButtom qoyildi. Boshqaruv qismiga 4 ta starbutton qo’yilgan. Birinchi formamizni dastur yozadigan qismiga quyidagi kodlani yozdik. //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" #include "Unit2.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::FormActivate(TObject *Sender) { if (FileExists("Kontaklar.txt")) { ListBox1->Items->LoadFromFile("Konteklar.txt"); } ListBox1 ->SetFocus(); }
void __fastcall TForm1::SpeedButton2Click(TObject *Sender)
void __fastcall TForm1::SpeedButton3Click(TObject *Sender) { if (ListBox1 ->Items ->Count <2) { ShowMessage("Tahrirlash uchun malumot yo'q") ; } else if (ListBox1 ->ItemIndex == -1) { ShowMessage("Tahrirlash uchub kontaktni tanlang"); } else{ index=(ListBox1 ->ItemIndex % 2 == 0) ? ListBox1 ->ItemIndex: ListBox1 ->ItemIndex-1 ; String fi=ListBox1 ->Items ->Strings [index]; String tel=ListBox1 ->Items ->Strings [index + 1]; String fam, ism; int pos2; pos2 = fi.Pos(" "); fam=fi.SubString(1,pos2-1) ; ism=fi.SubString(pos2+1, fi.Length() -pos2) ; Form2 ->eFam ->Text =fam; Form2 ->eIsm ->Text =ism; Form2 ->eTel ->Text =tel; Form2 ->Caption =".:: Kontaktni tahrirlash ::." ; Form2->eFam->ReadOnly=false; Form2->eIsm->ReadOnly=false; Form2->eTel->ReadOnly=false; Form2->ShowModal(); } } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton4Click(TObject *Sender) { if (ListBox1 ->Items ->Count <2) { ShowMessage("Ko'rish uchun malumot yo'q") ; } else if (ListBox1 ->ItemIndex == -1) { ShowMessage("Ko'rish uchun kontaktni tanlang"); } else{ index=(ListBox1 ->ItemIndex % 2 == 0) ? ListBox1 ->ItemIndex: ListBox1 ->ItemIndex-1 ; String fi=ListBox1 ->Items ->Strings [index]; String tel=ListBox1 ->Items ->Strings [index + 1]; String fam, ism; int pos2; pos2 = fi.Pos(" "); fam=fi.SubString(1,pos2-1) ; ism=fi.SubString(pos2+1, fi.Length() -pos2) ; Form2 ->eFam ->Text =fam; Form2 ->eIsm ->Text =ism; Form2 ->eTel ->Text =tel; Form2 ->Caption =".:: Kontaktni ko'rish ::." ; Form2->eFam->ReadOnly=true; Form2->eIsm->ReadOnly=true; Form2->eTel->ReadOnly=true; Form2->ShowModal(); } } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton5Click(TObject *Sender) { if (ListBox1 ->Items ->Count <2) { ShowMessage("O'chirish uchun malumot yo'q") ; } else if (ListBox1 ->ItemIndex == -1) { ShowMessage("O'chirish uchub kontaktni tanlang"); } else{ index=(ListBox1 ->ItemIndex % 2 == 0) ? ListBox1 ->ItemIndex: ListBox1 ->ItemIndex-1 ; int res=MessageDlg("Chindaham o'chirmoqchimisiz", mtWarning, TMsgDlgButtons()< ListBox1->Items->Delete(index+1); ListBox1->Items->Delete(index); Form1->ListBox1->Items->SaveToFile("Kontaktlar.txt") ; ShowMessage("o'chirildi"); } } } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton1Click(TObject *Sender) { if (Edit1->Text.Trim() != "") { for (int i=0; i < ListBox1->Items->Count; i++) { if (ListBox1->Items->Strings[i].Pos(Edit1->Text.Trim())> 0){ ListBox1->ItemIndex=i; return; } } } } Endi Form2 oynasiga quyidagicha ko’rinish beramiz: Bu qismda 3 ta lebel 3 ta edit va ikta starbutton qoyilgan (Izohga hojat yoq!)
#include #pragma hdrstop #include "Unit2.h" #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm2 *Form2; //--------------------------------------------------------------------------- __fastcall TForm2::TForm2(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm2::SpeedButton3Click(TObject *Sender) { Close() ; } //--------------------------------------------------------------------------- void __fastcall TForm2::FormActivate(TObject *Sender) { eFam ->SetFocus() ; } //--------------------------------------------------------------------------- void __fastcall TForm2::SpeedButton2Click(TObject *Sender) { String fam, ism, tel; fam=eFam ->Text .Trim() ; ism=eIsm ->Text .Trim() ; tel=eTel ->Text .Trim() ; if (fam == ""){ ShowMessage("Familyani kiriting.") ; eFam->SetFocus() ; } else if (ism == "") { ShowMessage("Ismni kiriting."); eIsm->SetFocus() ; } else if (tel == "") { ShowMessage("Telefon raqamini kiriting."); eTel->SetFocus() ; } else { if (Form2 ->Caption == ".:: Yangi kontakt qo'shish ::.") { //qo'shish Form1->ListBox1->Items->Add(fam+" "+ism); Form1->ListBox1->Items->Add(tel); Form1->ListBox1->Items->SaveToFile("Kontaktlar.txt") ; } else{ //tahrirlash Form1 ->ListBox1 ->Items ->Strings [Form1-> index]= fam + " " + ism; Form1 ->ListBox1 ->Items ->Strings [Form1->index +1]= tel; } Close() ; } }
Download 53.06 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling