在pannel上放一个image和二个scrollbar
在scrollbar的onclick事件中利用scrollbar.position属性改变image的top,left

解决方案 »

  1.   

    先在窗体中放入一个ScrollBox1,在其上面放上image1,加入图片
    在formcreate中加入以下代码:
       image1.width:=image1.picture.width;
       image1.height:=image1.picture.height;
    如果你的图片比scrollbox1要大,运行后你就能看到效果了.
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtDlgs, StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        Panel1: TPanel;
        Image1: TImage;
        Button1: TButton;
        OpenPictureDialog1: TOpenPictureDialog;
        ScrollBar1: TScrollBar;
        ScrollBar2: TScrollBar;
        procedure Button1Click(Sender: TObject);
        procedure ScrollBar2Scroll(Sender: TObject; ScrollCode: TScrollCode;
          var ScrollPos: Integer);
        procedure ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
          var ScrollPos: Integer);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
         if OpenPictureDialog1.Execute then  begin
            image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
            image1.Width:=image1.Picture.Width;
            image1.Height:=image1.Picture.Height;
            if image1.Width>panel1.ClientWidth then begin
               ScrollBar1.Max:=image1.Width-panel1.ClientWidth+scrollbar2.Width;
               ScrollBar1.LargeChange:=100;
               ScrollBar1.Visible:=true;
            end
            else
                ScrollBar1.Visible:=False;
            if image1.Height>panel1.ClientHeight then begin
               ScrollBar2.Max:=image1.Height-panel1.ClientHeight+scrollbar1.Height;
               ScrollBar2.LargeChange:=100;
               ScrollBar2.Visible:=true ;
            end
            else
                ScrollBar2.Visible:=False;
         end;end;procedure TForm1.ScrollBar2Scroll(Sender: TObject; ScrollCode: TScrollCode;
      var ScrollPos: Integer);
    begin
         image1.Top:=0-scrollpos;
    end;procedure TForm1.ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
      var ScrollPos: Integer);
    begin
         image1.Left:=0-ScrollPos;
    end;end.