全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1090
推到 Plurk!
推到 Facebook!

Delphi 子窗體中 為何 無法打開 文件打開對話框?

答題得分者是:老大仔
flagshang
一般會員


發表:5
回覆:6
積分:2
註冊:2008-03-30

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-02-22 22:41:29 IP:221.224.xxx.xxx 未訂閱
各位先進,請教一個菜問題,

Delphi 子窗體中 為何 無法打開 文件打開對話框? 為什么? 有什么等效的方法。

我的目的是在 子窗體 中打開 文件打開對話框,加載一副圖片給子窗體上的IMAGE組件。

感謝~
老大仔
尊榮會員


發表:78
回覆:837
積分:1088
註冊:2006-07-06

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-02-23 00:31:53 IP:59.114.xxx.xxx 未訂閱
看看以下是不是你要的


[code delphi]
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
Image1.Picture.LoadFromFile(OpenDialog1.FileName);
end;

[/code]
編輯記錄
老大仔 重新編輯於 2009-02-23 00:33:51, 註解 無‧
zhouying82
高階會員


發表:150
回覆:272
積分:189
註冊:2004-03-16

發送簡訊給我
#3 引用回覆 回覆 發表時間:2009-02-23 10:06:58 IP:222.70.xxx.xxx 訂閱
哎呀,来晚了一步,呵呵
------
断断续续的学了几年,还是一个初学者,永远支持Delphi !
flagshang
一般會員


發表:5
回覆:6
積分:2
註冊:2008-03-30

發送簡訊給我
#4 引用回覆 回覆 發表時間:2009-02-23 18:45:32 IP:124.219.xxx.xxx 未訂閱
感謝 老大仔 的代碼,感謝 zhouying82 的關注,補上我的代碼如下;

unit1是父窗體,unit3是子窗體,unit8是軟體開啟時的閃動窗體。
當通過unit1上的menu 打開unit3后,unit3上的代碼與 老大仔 的指教類似,但是想打開 圖片打開對話框,卻報錯,還請各位先進在指點,感恩。。。


project1
--------------------------------------------------------
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit3 in 'Unit3.pas' {Form3},
Unit8 in 'Unit8.pas' {SplashForm};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TSplashForm, SplashForm);
Application.Run;
end.
--------------------------------------------------------
Unit1
-------------------------------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ComCtrls, jpeg, ExtCtrls;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
Search1: TMenuItem;
Edit1: TMenuItem;
procedure Edit1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure aa(var xx: TWMGetMinMaxinfo); message WM_GetMinMaxinfo;
end;
var
Form1: TForm1;
implementation
uses Unit3;
{$R *.dfm}
procedure TForm1.aa(var xx: TWMGetMinMaxinfo);
begin
with xx.MinMaxInfo^ do
begin
ptMinTrackSize := point(610,431);
ptMaxTrackSize := point(610,431);
end;
end;
procedure TForm1.Edit1Click(Sender: TObject);
var form3:tForm3;
begin
Form3:=tForm3.create(self);
form3.show;
form3.WindowState:=wsMaximized;
end;
end.
-------------------------------------------------------
Unit3
------------------------------------------------------
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, DBCtrls, Grids, DBGrids, DB, DBTables, StdCtrls,
Buttons, ExtDlgs;
type
TForm3 = class(TForm)
Button1: TButton;
Image1: TImage;
OpenPictureDialog1: TOpenPictureDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
uses Unit1;
{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject);
begin
form3.OpenPictureDialog1.Execute;
form3.Image1.Picture.LoadFromFile(openpicturedialog1.FileName);
end;
end.
-------------------------------------------------------
unit8
------------------------------------------------------
unit Unit8;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, jpeg;
type
TSplashForm = class(TForm)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
SplashForm: TSplashForm;
implementation
{$R *.DFM}
procedure TSplashForm.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled:=false;
Close;
end;
procedure TSplashForm.FormShow(Sender: TObject);
begin
SetWindowPos(Handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE);
end;
end.
------------------------------------------------------
老大仔
尊榮會員


發表:78
回覆:837
積分:1088
註冊:2006-07-06

發送簡訊給我
#5 引用回覆 回覆 發表時間:2009-02-23 21:00:20 IP:220.140.xxx.xxx 未訂閱
procedure TForm1.Edit1Click(Sender: TObject);
var form3:tForm3; <---這行不用
begin
Form3:=tForm3.create(self); <---這行也不用
form3.show;
form3.WindowState:=wsMaximized;
end;


這樣應該就ok了~
系統時間:2024-05-15 19:42:54
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!