Смекни!
smekni.com

Алгоритм, написание и отладка программы "Текстовый редактор" (стр. 3 из 3)

else

StartPos = 0;

ToEnd = RichEdit1->Text.Length() - StartPos;

FoundAt = RichEdit1->FindText(FindDialog1->FindText, StartPos, ToEnd, TSearchTypes()<< stMatchCase);

if (FoundAt != -1)

{

RichEdit1->SetFocus();

RichEdit1->SelStart = FoundAt;

RichEdit1->SelLength = FindDialog1->FindText.Length();

}

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N9Click(TObject *Sender)

{

if (MessageBox(0,"Сохранить содержимое окна редактирования? ","Подтвердите сохранение",MB_YESNO)==IDYES)

if (SaveDialog1->Execute()) RichEdit1->Lines->SaveToFile(SaveDialog1->FileName);

Application->Terminate();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N16Click(TObject *Sender)

{

if (RichEdit1->Lines->Count>0)

{

if (MessageBox(0,"Сохранитьсодержимоеокнаредактирования? ","Подтвердите сохранение",MB_YESNO)==IDYES)

{

//N9Click(Sender);

}

}

RichEdit1->Clear();

StatusBar1->Panels->Items[0]->Text="Документ";

}

//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton2Click(TObject *Sender)

{

RichEdit1->CutToClipboard();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton5Click(TObject *Sender)

{

RichEdit1->CopyToClipboard();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton9Click(TObject *Sender)

{

RichEdit1->PasteFromClipboard();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N20Click(TObject *Sender)

{

ReplaceDialog1->Execute();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::ReplaceDialog1Replace(TObject *Sender)

{

TReplaceDialog *dlg = (TReplaceDialog *)Sender;

int SelPos = RichEdit1->Lines->Text.Pos(dlg->FindText);

if (SelPos > 0)

{

RichEdit1->SelStart = SelPos - 1;

RichEdit1->SelLength = dlg->FindText.Length();

RichEdit1->SelText = dlg->ReplaceText;

}

else

MessageBeep(0);

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N19Click(TObject *Sender)

{

FindDialog1->Position = Point(RichEdit1->Left + RichEdit1->Width, RichEdit1->Top);

FindDialog1->Execute();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N30Click(TObject *Sender)

{

if(FontDialog1->Execute())

{

RichEdit1->SelAttributes->Assign(FontDialog1->Font);

}

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N28Click(TObject *Sender)

{

Application->CreateForm(__classid(TAboutBox), &AboutBox);

AboutBox->ShowModal();

AboutBox->Free();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N7Click(TObject *Sender)

{

if (PrintDialog1->Execute()) RichEdit1->Print(" ");

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N24Click(TObject *Sender)

{

StatusBar1->Visible=! StatusBar1->Visible;

N24->Checked=! N24->Checked;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N22Click(TObject *Sender)

{

Panel1->Visible=! Panel1->Visible;

N22->Checked=! N22->Checked;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N23Click(TObject *Sender)

{

Panel2->Visible=! Panel2->Visible;

N23->Checked=! N23->Checked;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton16Click(TObject *Sender)

{

if(ColorDialog1->Execute())

{RichEdit1->Color=ColorDialog1->Color;}

}

//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton17Click(TObject *Sender)

{

RichEdit1->Paragraph->Alignment=taLeftJustify;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton18Click(TObject *Sender)

{

RichEdit1->Paragraph->Alignment=taCenter;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton19Click(TObject *Sender)

{

if(SpeedButton11->Down==true)

{

RichEdit1->Paragraph->Numbering=nsBullet;

}

else

{

RichEdit1->Paragraph->Numbering=nsNone;

}

}

//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton15Click(TObject *Sender)

{

RichEdit1->Paragraph->Alignment=taRightJustify;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::CSpinEdit1KeyPress(TObject *Sender, char &Key)

{

if((Key!=VK_BACK)&&(Key!='9')&&(Key!='8')&&(Key!='7')&&(Key!='6'))

{

Set <char, '0','9'> Dig;

Dig << '0'<< '1'<< '2' << '3'<< '4' << '5'<< ' 6 '<< ' 7 '<< ' 8 '<< ' 9 ' ;

if ( ! Dig.Contains(Key)) { Key = 0; Beep () ;}

}

}

//---------------------------------------------------------------------------

void __fastcall TForm1::FormShow(TObject *Sender)

{

int i;

for (i=0; i<Screen->Fonts->Count; i++)

{

ComboBox1->Items->Add (Screen->Fonts->Strings[i] ) ;

}

CSpinEdit1->Value=RichEdit1->SelAttributes->Size;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::RichEdit1MouseUp(TObject *Sender,

TMouseButton Button, TShiftState Shift, int X, int Y)

{

if(RichEdit1->Paragraph->Numbering==nsNone)

{SpeedButton19->Down=false;}

if(RichEdit1->Paragraph->Numbering==nsBullet)

{SpeedButton19->Down=true;}

switch (RichEdit1->Paragraph->Alignment)

{case taLeftJustify: SpeedButton17->Down=true; break;

case taCenter: SpeedButton18->Down=true; break;

case taRightJustify: SpeedButton15->Down=true; break;}

if(RichEdit1->SelAttributes->Style==RichEdit1->SelAttributes->Style<<fsBold)

{SpeedButton13->Down=true;}

else{SpeedButton13->Down=false;}

if(RichEdit1->SelAttributes->Style==RichEdit1->SelAttributes->Style<<fsUnderline)

{SpeedButton11->Down=true;}

else{SpeedButton11->Down=false;}

if(RichEdit1->SelAttributes->Style==RichEdit1->SelAttributes->Style<<fsItalic)

{SpeedButton12->Down=true;}

else{SpeedButton12->Down=false;}

CSpinEdit1->Value=RichEdit1->SelAttributes->Size;

ComboBox1->ItemIndex = ComboBox1->Items->IndexOf(RichEdit1->SelAttributes->Name) ;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::RichEdit1KeyUp(TObject *Sender, WORD &Key,

TShiftState Shift)

{

if(RichEdit1->Paragraph->Numbering==nsNone)

{SpeedButton19->Down=false;}

if(RichEdit1->Paragraph->Numbering==nsBullet)

{SpeedButton19->Down=true;}

switch (RichEdit1->Paragraph->Alignment)

{case taLeftJustify: SpeedButton17->Down=true; break;

case taCenter: SpeedButton18->Down=true; break;

case taRightJustify: SpeedButton15->Down=true; break;}

if(RichEdit1->SelAttributes->Style==RichEdit1->SelAttributes->Style<<fsBold)

{SpeedButton13->Down=true;}

else{SpeedButton13->Down=false;}

if(RichEdit1->SelAttributes->Style==RichEdit1->SelAttributes->Style<<fsUnderline)

{SpeedButton11->Down=true;}

else{SpeedButton11->Down=false;}

if(RichEdit1->SelAttributes->Style==RichEdit1->SelAttributes->Style<<fsItalic)

{SpeedButton12->Down=true;}

else{SpeedButton12->Down=false;}

CSpinEdit1->Value=RichEdit1->SelAttributes->Size;

ComboBox1->ItemIndex = ComboBox1->Items->IndexOf(RichEdit1->SelAttributes->Name) ;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)

{

RichEdit1->Clear();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)

{

Action=caFree;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)

{

if(RichEdit1->Modified)

{

int res=Application->MessageBox("Текстдокументанесохранен. &bsol;n&bsol;n" "Сохранить документ в файле&bsol;n&bsol;n" "(Отмена - продолжение работы)", "Подтвердите завершение работы", MB_YESNOCANCEL+MB_ICONQUESTION);

switch(res)

{

case IDYES: N5Click(Sender); break;

case IDCANCEL: CanClose=false;

}

}

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N26Click(TObject *Sender)

{

Application->CreateForm(__classid(TForm2), &Form2);

Form2->Memo1->Lines->LoadFromFile("hlp");

Form2->ShowModal();

Form2->Free();

}