在看题之前恳求大家一定要看下去,我已经发过一个类似的问题了没人给解答,3天了一直不明白下面的程序怎么实现的,再次恳求大家耐心看完,本人菜鸟分不多,希望还请多多包涵书上的一道实例是这样的,一共有2个窗体,窗体1上面有2个image和一个button,窗体2是一些设置选项
程序作用:点击窗体1上的button弹出窗体2,然后对上面的选项进行选择,确定后退出,窗体1的图片会进行对应的修改
程序设计界面在下面的网址
http://hi.baidu.com/xuminghui3821/blog/item/952bf33cf24770e23c6d97d4.html窗体1代码unit MoreF;interfaceuses
Windows, Classes, Graphics, Forms,
Controls, ConfDial, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Image1: TImage;
Image2: TImage;
ConfigureButton: TButton;
procedure ConfigureButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.ConfigureButtonClick(Sender: TObject);
begin
ConfigureDialog.CheckBox1.Checked := image1.Visible;
ConfigureDialog.CheckBox2.Checked := image2.Visible;
if (image2.height=75) and (image2.width=75) then
ConfigureDialog.RadioGroup1.itemindex:=0
else
ConfigureDialog.RadioGroup1.ItemIndex:=1;
if (ConfigureDialog.ShowModal = mrOk) then
begin
Image1.Visible := ConfigureDialog.CheckBox1.Checked;
Image2.Visible := ConfigureDialog.CheckBox2.Checked;
if ConfigureDialog.RadioGroup1.ItemIndex=0 then
begin
image2.Left:=110;
image2.Top:=60;
image2.Height:=75;
image2.Width:=75;
end
else if ConfigureDialog.RadioGroup1.ItemIndex=1 then
begin
image2.Top:=15;
image2.Left:=70;
image2.Height:=150;
image2.Width:=150;
end;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
image1.Picture.LoadFromFile('1.bmp');
image2.Picture.loadfromfile('2.bmp');
end;end.
窗体2代码如下unit Confdial;interfaceuses
Windows, Classes, Graphics, Forms,
Controls, Buttons, StdCtrls, ExtCtrls;type
TConfigureDialog = class(TForm)
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
RadioGroup1: TRadioGroup;
private
{ Private declarations }
public
OldHeight, NewHeight: Integer;
end;var
ConfigureDialog: TConfigureDialog;implementation{$R *.DFM}
end.
程序我能看明白 我就是不知道点击窗体1的设置按钮如何弹出窗体2的
另外我按照这个例子写窗体1代码的时候只要碰到窗体2的一些设置就会报错,
我不明白如何将窗体1的设置按钮与窗体2联系起来的,恳请各位高手帮帮忙吧,菜鸟真的很痛苦啊
另外是否跟
uses中的ConfDial, StdCtrls, ExtCtrls这3个东西有关?
我新建了一个窗体经过比较发现多出了这3个东西,不知道有什么关系,还请帮忙解释一下最后
别太在意分,我实在是没有分可给,像我这样的菜鸟,会经常提问问题的,得分途径也很少,但恰恰我是真正需要帮助的人,各位高手帮帮忙啊
程序作用:点击窗体1上的button弹出窗体2,然后对上面的选项进行选择,确定后退出,窗体1的图片会进行对应的修改
程序设计界面在下面的网址
http://hi.baidu.com/xuminghui3821/blog/item/952bf33cf24770e23c6d97d4.html窗体1代码unit MoreF;interfaceuses
Windows, Classes, Graphics, Forms,
Controls, ConfDial, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Image1: TImage;
Image2: TImage;
ConfigureButton: TButton;
procedure ConfigureButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.ConfigureButtonClick(Sender: TObject);
begin
ConfigureDialog.CheckBox1.Checked := image1.Visible;
ConfigureDialog.CheckBox2.Checked := image2.Visible;
if (image2.height=75) and (image2.width=75) then
ConfigureDialog.RadioGroup1.itemindex:=0
else
ConfigureDialog.RadioGroup1.ItemIndex:=1;
if (ConfigureDialog.ShowModal = mrOk) then
begin
Image1.Visible := ConfigureDialog.CheckBox1.Checked;
Image2.Visible := ConfigureDialog.CheckBox2.Checked;
if ConfigureDialog.RadioGroup1.ItemIndex=0 then
begin
image2.Left:=110;
image2.Top:=60;
image2.Height:=75;
image2.Width:=75;
end
else if ConfigureDialog.RadioGroup1.ItemIndex=1 then
begin
image2.Top:=15;
image2.Left:=70;
image2.Height:=150;
image2.Width:=150;
end;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
image1.Picture.LoadFromFile('1.bmp');
image2.Picture.loadfromfile('2.bmp');
end;end.
窗体2代码如下unit Confdial;interfaceuses
Windows, Classes, Graphics, Forms,
Controls, Buttons, StdCtrls, ExtCtrls;type
TConfigureDialog = class(TForm)
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
RadioGroup1: TRadioGroup;
private
{ Private declarations }
public
OldHeight, NewHeight: Integer;
end;var
ConfigureDialog: TConfigureDialog;implementation{$R *.DFM}
end.
程序我能看明白 我就是不知道点击窗体1的设置按钮如何弹出窗体2的
另外我按照这个例子写窗体1代码的时候只要碰到窗体2的一些设置就会报错,
我不明白如何将窗体1的设置按钮与窗体2联系起来的,恳请各位高手帮帮忙吧,菜鸟真的很痛苦啊
另外是否跟
uses中的ConfDial, StdCtrls, ExtCtrls这3个东西有关?
我新建了一个窗体经过比较发现多出了这3个东西,不知道有什么关系,还请帮忙解释一下最后
别太在意分,我实在是没有分可给,像我这样的菜鸟,会经常提问问题的,得分途径也很少,但恰恰我是真正需要帮助的人,各位高手帮帮忙啊
从程序上看, 窗体2 是用Application自动创建的;
StdCtrls-标准空间单元,拖个TButton的界面上再保存下,就会自动引用;
ExtCtrls类似StdCtrls,还不明白自己查
能详细解释下么?
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm2, Form2);
代表Application创建了 窗体1 跟 窗体2;
但是为什么这出现 窗体1 呢?这里有个mainform的概念,排在前面的可视的就是mainform。可以尝试调换他们的创建顺序:
Application.CreateForm(TForm2, Form2);
Application.CreateForm(TForm1, Form1);
这个可以看【Project Options】里
begin
Form2.show;或者
Form2:=TForm2.Create(self);
Form2.showmodal;
end;
所有需要Show、ShowModal方法让其显示出来;
Show是普通显示,窗体1 跟 窗体2可以切换;
ShowModal是模态显示,知道 窗体2 关闭,否则 窗体1 无法获得焦点(Focus);
要使用某个类,就要引用该类所在的单元(uses ...)。
这句话中ShowModal表示已模态窗体弹出ConfigureDialog窗体,mrOk是窗体关闭时的返回值,如果返回这个值就执行if语句了。
你自己的写的时候报错,是因为你在Form1中 没有引用Confdial单元,可以手写,也可以File-Use Unit菜单进行操作。