unit Unit1;
interface
uses
Windows, Messages, Printers, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
Filer1: TMenuItem;
bn1: TMenuItem;
Gemsom1: TMenuItem;
N1: TMenuItem;
Afslut1: TMenuItem;
Om1: TMenuItem;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
Udskriv1: TMenuItem;
PrintDialog1: TPrintDialog;
Format1: TMenuItem;
FontDialog1: TFontDialog;
Skrifttype1: TMenuItem;
OmTeksteditoren1: TMenuItem;
memo1: TRichEdit;
Gem1: TMenuItem;
procedure Afslut1Click(Sender: TObject);
procedure bn1Click(Sender: TObject);
procedure Gemsom1Click(Sender: TObject);
procedure Udskriv1Click(Sender: TObject);
procedure Skrifttype1Click(Sender: TObject);
procedure OmTeksteditoren1Click(Sender: TObject);
procedure Gem1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
filnavn : string;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Afslut1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.bn1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
Memo1.Clear;
Memo1.Lines.LoadFromFile(Opendialog1.FileName);
end;
end;
procedure TForm1.Gemsom1Click(Sender: TObject);
begin
if SaveDialog1.Execute then
begin
Memo1.Lines.SaveToFile(SaveDialog1.FileName);
end;
end;
procedure TForm1.Udskriv1Click(Sender: TObject);
const TopMargen=20;
const LeftMargen=20;
const mellemrum=5;
var y,i:integer;
begin
with Printer do
begin
BeginDoc;
y:=0;
//Print alle linierne
for i:=0 to Memo1.Lines.Count-1 do begin
//Tjek for side skift
if y+Canvas.TextHeight(Memo1.Lines[i])+mellemrum>PageHeight Then begin newpage;y:=0;end;
//udskriv
Canvas.TextOut(LeftMargen,TopMargen+y,Memo1.Lines[i]);
//Flyt til næste linie
y:=y+Canvas.TextHeight(Memo1.Lines[i])+mellemrum;
end;
EndDoc;
end;
End;
procedure TForm1.Skrifttype1Click(Sender: TObject);
begin
FontDialog1.Font := memo1.Font;
if FontDialog1.Execute then
memo1.SelAttributes.Assign(FontDialog1.Font);
end;
procedure TForm1.OmTeksteditoren1Click(Sender: TObject);
begin
AboutBox.ShowModal;
end;
procedure TForm1.Gem1Click(Sender: TObject);
begin
if filnavn = '' then
begin
savedialog1.execute;
filnavn := savedialog1.filename;
end;
if filnavn = '' then else Memo1.Lines.SaveToFile (filnavn)
end;
end.
Hvor??