delphi控件visible使用的一个bug(是否bug)

btlxy 2006-10-16 11:36:48
1 在一个form1中,有一个page control,可以动态生成tabsheet
2 动态生成form2 ,放置在tabsheet上
3 在form2 中的show事件,可以改变控件的visible
问题:控件的visible=false ,控件可以看见。

form1源码:

unit FormPageForm;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ToolWin;

type
TForm1 = class(TForm)
ToolBar1: TToolBar;
btnPage: TToolButton;
PageControl1: TPageControl;
procedure btnPageClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

uses
FormInPage;

procedure TForm1.btnPageClick(Sender: TObject);
var
Form: TForm;
Sheet: TTabSheet;
begin
// create a tabsheet within the page control
Sheet := TTabSheet.Create(PageControl1);
Sheet.PageControl := PageControl1;
// create the form and place it in the tabsheet
Form := TForm2.Create (Application);
Form.BorderStyle := bsNone;
Form.Align := alClient;
Form.Parent := Sheet;
Form. Visible := True;
// activate and set title
PageControl1.ActivePage := Sheet;
Sheet.Caption := Form.Caption;
end;

end.


form2源码:
unit FormInPage;

interface

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

type
TForm2 = class(TForm)
RichEdit1: TRichEdit;
Edit1: TEdit;
Label1: TLabel;
Edit2: TEdit;
Label2: TLabel;
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.FormShow(Sender: TObject);
begin
Edit1.Visible:=False;
Label1.Visible :=False;
Edit2.Visible:=True;
Label2.Visible :=True;

Self.Repaint;

end;

end.


------------------------------
[?]忘各位能帮助解决,谢谢!
...全文
340 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
btlxy 2006-10-21
  • 打赏
  • 举报
回复
liangqingzhi(老之) :
其实属性值已经设置成功了,只是显示的问题了
comanche 2006-10-21
  • 打赏
  • 举报
回复
没想过要这么作, 另一种方法也可以把 Form 作为 PageControl 的 Sheet

Form := TForm2.Create (Application);
Form.ManualDock(PageControl1, nil, alClient);
Form.Visible := True; 这句完全等同于 Form.Show

这样作完后
Sheet.Caption = Form.Caption 代码激活某叶可以用这个
老之 2006-10-16
  • 打赏
  • 举报
回复
后来看了一下,OnShow里的其实是执行的,但被改了回来。问题是在PageControl1.ActivePage := Sheet;这一句,要放在Form. Visible := True;前面。
btlxy 2006-10-16
  • 打赏
  • 举报
回复
liangqingzhi(老之) :

请问;为何原来的操作就不可以呢?
老之 2006-10-16
  • 打赏
  • 举报
回复
将隐藏控件的代码放在OnCreate事件里面,或者在ToolButton点击事件里加一句Form.Show
btlxy 2006-10-16
  • 打赏
  • 举报
回复
大家执行时,点击form1中create page 按钮,多次,就可发现问题

5,928

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧