Logo New book: Delphi 2007 Handbook
My blog in online
Delphi tech support service: support.marcocantu.com
Google
  Web www.marcocantu.com

Menu for Development

Site Menu
Delphi 2007 Handbook
Mastering Borland Delphi 2005
Essential Pascal
Essential Delphi
Buy Books Online
Code Repository
Newsgroups
White Papers
Tools
Conferences
Training
Delphi Links
Contact Marco

My Other Sites
Italian Site (www.marcocantu.it)
Developers Newsgroups Browser (dev.newswhat.com)
My town (www.piazzacavalli.net)
the delphi search
Wintech Italia (my company)

Breaking News
Buy Mastering Borland Delphi 2005 from Amazon
Free ebook: Mastering Delphi Update for Delphi 2006

Advertising
Home My Blog Books My Bookstore Development Links Marco



Home: Code Repository: Mastering Delphi 5

Project IMAGEV2

Project Structure


IMAGEV2.DPR

program Imagev2;

uses
  Forms,
  ImageF in 'ImageF.pas' {ViewerForm};

{$R *.RES}

begin
  Application.CreateForm(TViewerForm, ViewerForm);
  Application.Run;
end.

IMAGEF.PAS

unit ImageF;

interface

uses Windows, Classes, Graphics, Forms, Controls, Menus,
  StdCtrls, Dialogs, ExtCtrls;

type
  TViewerForm = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Open1: TMenuItem;
    N1: TMenuItem;
    Exit1: TMenuItem;
    Help1: TMenuItem;
    AboutImageViewer1: TMenuItem;
    OpenDialog1: TOpenDialog;
    Options1: TMenuItem;
    Stretch1: TMenuItem;
    Image1: TImage;
    procedure Open1Click(Sender: TObject);
    procedure Stretch1Click(Sender: TObject);
    procedure Exit1Click(Sender: TObject);
    procedure AboutImageViewer1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  ViewerForm: TViewerForm;

implementation

              {$R *.DFM}

procedure TViewerForm.Open1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
    Image1.Picture.LoadFromFile (OpenDialog1.FileName);
end;

procedure TViewerForm.Stretch1Click(Sender: TObject);
begin
  Image1.Stretch := not Image1.Stretch;
  Stretch1.Checked := Image1.Stretch;
  if Image1.Stretch then
    Image1.Align := alClient
  else
  begin
    Image1.Align := alNone;
    Image1.Height := Image1.Picture.Height;
    Image1.Width := Image1.Picture.Width;
  end;
end;

procedure TViewerForm.Exit1Click(Sender: TObject);
begin
  Close;
end;

procedure TViewerForm.AboutImageViewer1Click(Sender: TObject);
begin
  MessageDlg ('Image Viewer, written by Marco Cantù',
    mtInformation, [mbOk], 0);
end;

end.

IMAGEF.DFM

object ViewerForm: TViewerForm
  Left = 204
  Top = 171
  Width = 422
  Height = 345
  Caption = 'Image Viewer'
  Font.Color = clWindowText
  Font.Height = -13
  Font.Name = 'System'
  Font.Style = []
  Menu = MainMenu1
  PixelsPerInch = 96
  TextHeight = 16
  object Image1: TImage
    Left = 0
    Top = 0
    Width = 17
    Height = 17
    AutoSize = True
  end
  object MainMenu1: TMainMenu
    Left = 24
    Top = 8
    object File1: TMenuItem
      Caption = '&File'
      object Open1: TMenuItem
        Caption = '&Open...'
        OnClick = Open1Click
      end
      object N1: TMenuItem
        Caption = '-'
      end
      object Exit1: TMenuItem
        Caption = '&Exit'
        OnClick = Exit1Click
      end
    end
    object Options1: TMenuItem
      Caption = '&Options'
      object Stretch1: TMenuItem
        Caption = '&Stretch'
        OnClick = Stretch1Click
      end
    end
    object Help1: TMenuItem
      Caption = '&Help'
      object AboutImageViewer1: TMenuItem
        Caption = '&About Image Viewer...'
        OnClick = AboutImageViewer1Click
      end
    end
  end
  object OpenDialog1: TOpenDialog
    FileEditStyle = fsEdit
    Filter = 'Bitmap (*.bmp)|*.bmp|Icon (*.ico)|*.ico|Metafile (*.wmf)|*.wmf'
    Options = [ofHideReadOnly, ofPathMustExist, ofFileMustExist]
    Left = 88
    Top = 8
  end
end