www.pudn.com > TSimpleGraph.rar > Unit1.pas, change:2012-05-16,size:3819b


unit Unit1; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, SimpleGraph; 
 
type 
  TForm1 = class(TForm) 
    scrlbx1: TScrollBox; 
    smplgrph1: TSimpleGraph; 
    procedure FormCreate(Sender: TObject); 
    procedure smplgrph1MouseDown(Sender: TObject; Button: TMouseButton; 
      Shift: TShiftState; X, Y: Integer); 
    procedure smplgrph1MouseMove(Sender: TObject; Shift: TShiftState; X, 
      Y: Integer); 
    procedure repaint(); 
    procedure smplgrph1MouseWheelDown(Sender: TObject; Shift: TShiftState; 
      MousePos: TPoint; var Handled: Boolean); 
    procedure smplgrph1MouseWheelUp(Sender: TObject; Shift: TShiftState; 
      MousePos: TPoint; var Handled: Boolean); 
  private 
    { Private declarations } 
  public 
    { Public declarations } 
    BeginX,BeginY:Integer; 
  end; 
 
var 
  Form1: TForm1; 
 
implementation 
 
{$R *.dfm} 
procedure Tform1.repaint(); 
begin 
  smplgrph1.Width := smplgrph1.Picture.Width * smplgrph1.Zoom div 100; 
  smplgrph1.Height := smplgrph1.Picture.Height * smplgrph1.Zoom div 100; 
  //smplgrph1.Top := scrlbx1.Top + (scrlbx1.Height - smplgrph1.Height) div 2 -50; 
 // smplgrph1.Left := (scrlbx1.Width - smplgrph1.Width) div 2+2; 
  scrlbx1.HorzScrollBar.Range:=smplgrph1.Width; 
  scrlbx1.VertScrollBar.Range:=smplgrph1.Height; 
end; 
 
procedure TForm1.FormCreate(Sender: TObject); 
var 
  FileName:string; 
begin 
  smplgrph1.Top:=0; 
  smplgrph1.Left:=0; 
  if not FileExists(FileName) then 
    FileName := ExtractFilePath(Application.ExeName)+'Road.bmp'; 
  smplgrph1.Picture.LoadFromFile(FileName); 
  smplgrph1.Width:=smplgrph1.Picture.Width; 
  smplgrph1.Height:=smplgrph1.Picture.Height; 
 
  scrlbx1.HorzScrollBar.Range:=smplgrph1.Width; 
  scrlbx1.VertScrollBar.Range:=smplgrph1.Height; 
 
 
 
end; 
 
procedure TForm1.smplgrph1MouseDown(Sender: TObject; Button: TMouseButton; 
  Shift: TShiftState; X, Y: Integer); 
begin 
 
   BeginX := X; 
   BeginY := Y; 
 
   // TSimpleGraph(Sender).mousedownpos.X := x; 
  //TSimpleGraph(Sender).mousedownpos.y := y; 
end; 
 
procedure TForm1.smplgrph1MouseMove(Sender: TObject; Shift: TShiftState; X, 
  Y: Integer); 
begin 
   if [ssLeft] = Shift then 
   begin 
     
   if TScrollBox(TSimpleGraph(Sender).Parent).ClassName = 'TScrollBox' then 
    begin 
      if BeginX > x then 
        TScrollBox(TSimpleGraph(Sender).Parent).HorzScrollBar.Position := TScrollBox(TSimpleGraph(Sender).Parent).HorzScrollBar.Position 
          + Abs(x - BeginX ) 
      else 
        TScrollBox(TSimpleGraph(Sender).Parent).HorzScrollBar.Position := TScrollBox(TSimpleGraph(Sender).Parent).HorzScrollBar.Position 
          - Abs(x - BeginX ); 
 
      if BeginY> y then 
        TScrollBox(TSimpleGraph(Sender).Parent).VertScrollBar.Position := TScrollBox(TSimpleGraph(Sender).Parent).VertScrollBar.Position 
          + Abs(y - BeginY) 
      else 
        TScrollBox(TSimpleGraph(Sender).Parent).VertScrollBar.Position := TScrollBox(TSimpleGraph(Sender).Parent).VertScrollBar.Position 
          - Abs(y - BeginY); 
    end; 
    end; 
end; 
 
 
procedure TForm1.smplgrph1MouseWheelDown(Sender: TObject; 
  Shift: TShiftState; MousePos: TPoint; var Handled: Boolean); 
begin 
     if (smplgrph1.Zoom *smplgrph1.Picture.Width div 100 >scrlbx1.Width) and 
     (smplgrph1.Zoom*smplgrph1.Picture.Height div 100>scrlbx1.Height) then 
     begin 
     smplgrph1.Zoom := smplgrph1.Zoom - 1; 
     repaint; 
     end; 
 
end; 
 
procedure TForm1.smplgrph1MouseWheelUp(Sender: TObject; Shift: TShiftState; 
  MousePos: TPoint; var Handled: Boolean); 
begin 
    if smplgrph1.Zoom>100 then 
    begin 
      smplgrph1.Zoom:=100; 
      repaint; 
    end 
    else 
    begin 
      smplgrph1.Zoom:=smplgrph1.Zoom+1; 
      repaint; 
    end; 
 
end; 
 
end.