狼行神码

导航

打开图片

窗体设计如图:

image button OpenPictureDialog 各一个

代码:

 1 unit Unit1;
 2 
 3 interface
 4 
 5 uses
 6   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
 7   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtDlgs, Vcl.StdCtrls, Vcl.ExtCtrls;
 8 
 9 type
10   TForm1 = class(TForm)
11     Image1: TImage;
12     Button1: TButton;
13     OpenPictureDialog1: TOpenPictureDialog;
14     procedure Button1Click(Sender: TObject);
15   private
16     { Private declarations }
17   public
18     { Public declarations }
19   end;
20 
21 var
22   Form1: TForm1;
23 
24 implementation
25 
26 {$R *.dfm}
27 
28 procedure TForm1.Button1Click(Sender: TObject);
29 var
30   openfilepath:string;
31 begin
32   if OpenPictureDialog1.Execute then
33   begin
34     openfilepath := OpenPictureDialog1.FileName;//把打开文件名字赋值给openfilepath
35     Image1.Picture.LoadFromFile(openfilepath);  //在image1打开图片
36   end;
37 
38 end;
39 
40 end.

 

posted on 2016-10-21 11:10  狼行神码  阅读(456)  评论(0编辑  收藏  举报