.


:




:

































 

 

 

 


, 1-

. .

:

1. My Viewer and Editor , . : 1) ; 2) , ; 3) (Save as) .

2. , .

: Windows . , .

ճ :

, 1-

1. : Memo1, Button1, BitBtn1 ( Additional), OpenDialog1 ( Dialogs). Kind BitBtn1 bkClose. .

OpenDialog1 - , . ( OpenDialog1->Execute) Windows . Memo1 , . , Memo1, Lines.

2. Memo1 : ReadOnly True ( Memo1 ), ScrollBars ssBoth ( Memo1 : ). Lines Memo1. Caption Button1 Form1 , :

3. OnClick Button1. Load File , . FileName OpenDialog1. Button1Click :

void __fastcall TForm1::Button1Click(TObject *Sender)

{

if (OpenDialog1->Execute() && FileExists(OpenDialog1->FileName))

{

s=OpenDialog1->FileName;

Form1->Caption=s;

Memo1->Lines->LoadFromFile(s);

}

}

FileExists , OpenDialog1->FileName .

private TForm1 s:

class TForm1: public TForm

{

__published: // IDE-managed Components

TMemo *Memo1;

TButton *Button1;

TBitBtn *BitBtn1;

TOpenDialog *OpenDialog1;

void __fastcall Button1Click(TObject *Sender);

private:

// User declarations

AnsiString s;

public: // User declarations

__fastcall TForm1(TComponent* Owner);

};

Form1->Caption=s;

.

LoadFromFile Memo1.Lines s Memo1.Lines ( ). Memo1 .

4. . .

5. ϳ . , Filter OpenDialog1. ³ Filter Editor Filter ( ) :

.

, (, D:\students) InitialDir OpenDialog1.

6. . .

7. . OnResize :

void __fastcall TForm1::FormResize(TObject *Sender)

{

Memo1->Height=Form1->ClientHeight;

Memo1->Width=Form1->ClientWidth-20-Button1->Width;

Button1->Left=Form1->ClientWidth-10-Button1->Width;

Button1->Top=Form1->ClientHeight-4*Button1->Height;

BitBtn1->Left=Form1->ClientWidth-10-Button1->Width;

BitBtn1->Top=Form1->ClientHeight-2*Button1->Height;

}

8. Form1->ClientHeight Form1->ClientWidth 볺 ( ). Height Width , Left Top 볺 . , , Memo1 25 ( Height), Memo1 10 , .

TForm1->FormResize. TForm1->FormResize , Memo1 볺 , , 10 . , , .

9. Memo1 .

1- , 2-

1. File/Save as File/Save Project as Unit1.cpp Project1.bpr - . , .

2. , Memo1 ReadOnly Memo1 False. SaveDialog ( Dialogs) Button2. Caption Button2 Save File.

3. TForm1->.FormResize , Memo1 :

void __fastcall TForm1::FormResize(TObject *Sender)

{

Memo1->Height=Form1->ClientHeight;

Memo1->Width=Form1->ClientWidth-20-Button1->Width;

Button1->Left=Form1->ClientWidth-10-Button1->Width;

Button1->Top=Form1->ClientHeight-6*Button1->Height;

Button2->Left=Form1->ClientWidth-10-Button1->Width;

Button2->Top=Form1->ClientHeight-4*Button1->Height;

BitBtn1->Left=Form1->ClientWidth-10-Button1->Width;

BitBtn1->Top=Form1->ClientHeight-2*Button1->Height;

 

}

4. , FormResize .

5. , Memo1 , private TForm FileIsOpen :

private:

// User declarations

AnsiString s;

Boolean FileIsOpen;

6. Unit1.cpp ProgramName, :

const char *ProgramName="My Viewer and Editor";

7. Form1 Form1Create 䳿 OnCreate ( ):

void __fastcall TForm1::FormCreate(TObject *Sender)

{

FileIsOpen=False; //

Caption=ProgramName;

}

Caption=ProgramName;

.

8. 䳿 OnClick Button1 Load File , , :

void __fastcall TForm1::Button1Click(TObject *Sender)

{

if (FileIsOpen)

if (Application->MessageBox("×è çàïèñàòè çì³íè ó ôàéë?",

"Çðîá³òü ï³äòâåðäæåííÿ",MB_YESNO)==IDYES)

Memo1->Lines->SaveToFile(s);

if (OpenDialog1->Execute() && FileExists(OpenDialog1->FileName))

{ FileIsOpen=True;

s=OpenDialog1->FileName;

Form1->Caption=s;

Memo1->Lines->LoadFromFile(s);}

else

FileIsOpen=False;

}

, , Application.MessageBox, :

Application->MessageBox , , . , MB_YESNO , . IDYES , . MessageBox (, F1).

9. OnClick Button2 Save File , , , , , , , SaveDialog1 ( , New).

void __fastcall TForm1::Button2Click(TObject *Sender)

{

if (FileExists(s))

{ if (Application->MessageBox("×è çàïèñàòè çì³íè ó ôàéë?",

"Çðîá³òü ï³äòâåðäæåííÿ",MB_YESNO)==IDYES)

Memo1->Lines->SaveToFile(s);

}

else

if (SaveDialog1->Execute())

{ s=SaveDialog1->FileName;

Form1->Caption=s;

Memo1->Lines->SaveToFile(s);

}

}

SaveToFile Memo1->Lines s Memo1.

10. Load File Save File. : 1) Memo1 ; 2) , Memo1 ( ) .

1- , 3-

1. ³ . File/Save as File/Save Project as Unit1.cpp Project1.bpr 3- .

2. Button3 Button4 Save as New . : New, Load File, Save File, Save as, Close.

3. TForm1.FormResize:

void __fastcall TForm1::FormResize(TObject *Sender)

{

Memo1->Height=Form1->ClientHeight;

Memo1->Width=Form1->ClientWidth-20-Button1->Width;

Button4->Left=Form1->ClientWidth-10-Button1->Width;

Button4->Top=Form1->ClientHeight-10*Button1->Height;

Button1->Left=Form1->ClientWidth-10-Button1->Width;

Button1->Top=Form1->ClientHeight-8*Button1->Height;

Button2->Left=Form1->ClientWidth-10-Button1->Width;

Button2->Top=Form1->ClientHeight-6*Button1->Height;

Button3->Left=Form1->ClientWidth-10-Button1->Width;

Button3->Top=Form1->ClientHeight-4*Button1->Height;

BitBtn1->Left=Form1->ClientWidth-10-Button1->Width;

BitBtn1->Top=Form1->ClientHeight-2*Button1->Height;

}

4. , OnResize .

5. OnClick Button4 ( New):

void __fastcall TForm1::Button4Click(TObject *Sender)

{

if (FileIsOpen)

{ if (Application->MessageBox("×è çàïèñàòè çì³íè ó ôàéë?",

"Çðîá³òü ï³äòâåðäæåííÿ",MB_YESNO)==IDYES)

Memo1->Lines->SaveToFile(s);

}

Memo1->Lines->Clear();

FileIsOpen=False;

s="";

Caption=ProgramName;

}

, Memo1 New . , , , , .

Clear Memo1->Lines , , Memo1.

Caption=ProgramName;

, , .

6. OnClick Button3 ( Save as):

void __fastcall TForm1::Button3Click(TObject *Sender)

{

if (SaveDialog1->Execute())

{ s=SaveDialog1->FileName;

Form1->Caption=s;

Memo1->Lines->SaveToFile(s);

}

}

Memo1 .

7. . exe- Widows.

 

 

:

1. SaveDialog1, 1, ( Filter SaveDialog1). , , OpenDialog1.

2. ϳ 1- , ( ProgramName), , . ϳ ( New) , New file.

 

 

2-

1. : Memo1 , 볺 ( Align alClient, ScrollBars ssBoth), OpenDialog1 SaveDialog1, MainMenu1.

, .

2. . Items MainMenu1. . , () (), ᒺ Caption . .

Unit1.h :

class TForm1: public TForm

{

__published: // IDE-managed Components

TMemo *Memo1;

TOpenDialog *OpenDialog1;

TSaveDialog *SaveDialog1;

TMainMenu *MainMenu1;

TMenuItem *File1;

TMenuItem *About1;

TMenuItem *New1;

TMenuItem *LoadFile1;

TMenuItem *SaveFile1;

TMenuItem *Saveas1;

TMenuItem *Quit1;

private: // User declarations

public: // User declarations

__fastcall TForm1(TComponent* Owner);

};

TForm1 ᒺ TMenuItem, . , , OnClick. . .

3. About :

void __fastcall TForm1::About1Click(TObject *Sender)

{

ShowMessage("Copyright by ,"

"student of TDTU, Ukraine, 2006");

}

ShowMessage Ok.

4. ϳ Quit :

void __fastcall TForm1::Quit1Click(TObject *Sender)

{

Close();

}

5. .



<== | ==>
V- | MS Word.
:


: 2015-10-01; !; : 267 |


:

:

. .
==> ...

1663 - | 1593 -


© 2015-2024 lektsii.org - -

: 0.065 .