有2个窗体,窗体1中创建了窗体2,然后用showmodul显示它.想问在窗体2中有个名称为"应用"的按钮想控制窗体1中窗体的状态(好比颜色)可以实现么?如何实现.
注意:1.是showmodul显示.我用消息传递,但是好像会出异常,所以如果showmodul不行,那么模拟实现的也可以;
2.想要告诉在按钮点击处理中加入form1.color=...的请先思考如何避免"Circular unit reference "的错误.
注意:1.是showmodul显示.我用消息传递,但是好像会出异常,所以如果showmodul不行,那么模拟实现的也可以;
2.想要告诉在按钮点击处理中加入form1.color=...的请先思考如何避免"Circular unit reference "的错误.
解决方案 »
- 今日面试题目:adoquery 访问储存过程,返回N个数据集,但是只取第三个!
- 关于combobox问题,简单就是不会
- 窗口停靠的问题,急!
- 用Indy的IdMessage组件封装邮件,怎样才能让它不对主题进行Base64编码?
- 怎样把主窗口上的Caption字体从右向左移动
- 散分!!!回到CSDN!!
- 请问如何实现类似delphi中project-option窗体中的窗体列表的功能。
- 打印发票的问题?
- query+updateSQL更新时出现"General SQL Error"错误
- 这条语句为什么不执行?
- c/s两层开发的数据更新问题?
- 简单问题:DateTimePicker1 中的值 赋予一个 string
begin
Application.CreateForm(TForm2, Form2);
Form2.ShowModal;
Form2.Free;
end;
unit2
procedure TForm2.Button1Click(Sender: TObject);
begin
Form1.Color := clBlue;
end;不会出错呀!!!!!!!!!
uses 另一窗体的单元文件
再在按钮点击处理中加入form1.color=...
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementationuses Unit2;{$R *.dfm}//打开From2
procedure TForm1.Button1Click(Sender: TObject);
var
FrmColor:TColor;
begin
FrmColor := Form1.Color;
if OpenFrm2(FrmColor) then
Form1.Color := FrmColor;
end;end.//窗体2
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TForm2 = class(TForm)
Button1: TButton;
ColorBox1: TColorBox;
procedure Button1Click(Sender: TObject);
private
bReturn: Boolean;
MyColor: TColor;
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;
function OpenFrm2(var c:TColor):Boolean;
implementationfunction OpenFrm2(var c:TColor):Boolean;
var
Frm2: TForm2;
begin
try
Frm2 := TForm2.Create(nil);
Frm2.ShowModal;
c := Frm2.MyColor;
result := Frm2.bReturn;
finally
Frm2.Free;
Frm2 := nil;
end;
end;{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
begin
MyColor := ColorBox1.Selected;
bReturn := True;
close;
end;end.
luke5678(奇异)所写的就可以了吧,
一个那样的问题,有必要用消息吗?
这样是最简单的了
但是可能是问题写的不清楚,我想实现"应用"这个功能,也就是Form2在不关闭的情况下通过"应用"来调整Form1的颜色.否则的话直接在Form1的procedure TForm1.Button1Click(Sender: TObject);加入:
if Form2.ShowModal=2 then self.Color:=Form2.ColorBox1.Selected;
不过这个问题经大家的点拨还是解决了,关键在于meiqingsong(阿飛):两个都在implementation 下面 或一个在 implementation 一个在 interface 下面uses 另一窗体的单元文件;
代码如下:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, unit2, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
form2.ShowModal;
end;end.
-------------------------------------------------------------
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TForm2 = class(TForm)
ColorBox1: TColorBox;
Button1: TButton;
procedure ColorBox1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;implementation{$R *.dfm}
uses
unit1;procedure TForm2.ColorBox1Change(Sender: TObject);
begin
form1.Color:=self.ColorBox1.Selected;
end;end.
Form1: TForm1;implementation
uses unit2;
{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
form2.showmodal;
end;
end.
var
Form2: TForm2;implementation
uses unit1;
{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
begin
if ColorDialog1.Execute then
form1.Color:=ColorDialog1.Color;
end;end.Windows2000+D6測試通過~~~