線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:970
推到 Plurk!
推到 Facebook!

子視窗關閉重新執行程式

答題得分者是:pceyes
bluerurutia
一般會員


發表:1
回覆:0
積分:0
註冊:2008-11-28

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-11-28 12:44:41 IP:59.127.xxx.xxx 訂閱
如果我開了一個圖

把圖開在子視窗

當我把子視窗關掉的時候

希望程式可以回到剛開啟 尚未執行任何效果的狀態

標題重新執行程式不是真的關子視窗連主程式都關掉又重開

只是希望在我把全部的子視窗都關掉之後

能回到剛開起程式的時候

要怎麼寫呢QQ
pceyes
尊榮會員


發表:70
回覆:657
積分:1140
註冊:2003-03-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-11-28 14:45:03 IP:122.118.xxx.xxx 訂閱
1. 在Form1上拉二個Button
2. File -> New -> Form 兩次 (加入兩個新Form)
3. Project -> Options -> Forms 將Form2及Form3 由Available forms:
4. 檢查你的Unit1, Unit2, Unit3和我的沒有不同,編譯後測測看,是不是你要的。


[code delphi]
// 這是你的主程式
unit Unit1;

interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
{$R *.dfm}
uses Unit2,Unit3; // uses 你的子視窗
// 按鍵開啟你的子視窗 form2
procedure TForm1.Button1Click(Sender: TObject);
begin
form2 := TForm2.Create(application); // 動態產生你的子視窗
if form2.ShowModal = mrok then begin
showmessage('mrok');
end;

end;
// 按鍵開啟你的子視窗 form3
procedure TForm1.Button2Click(Sender: TObject);
begin
form3 := TForm3.Create(application); // 動態產生你的子視窗
if form3.ShowModal = mrNo then begin
showmessage('mrNo');
end;

end;
end.

[/code]

[code delphi]
// 子程式1
unit Unit2;

interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;

type
TForm2 = class(TForm)
Button1: TButton;
Image1: TImage;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
modalresult := mrok;
end;

end.

[/code]

[code delphi]
// 子程式2
unit Unit3;

interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm3 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form3: TForm3;

implementation
{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject);
begin
modalresult := mrNo;
end;

end.

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