1 在一个form1中,有一个page control,可以动态生成tabsheet
2 动态生成form2 ,放置在tabsheet上
3 在form2 中的show事件,可以改变控件的visible
问题:控件的visible=false ,控件可以看见。form1源码:unit FormPageForm;interfaceuses
  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;interfaceuses
  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.
------------------------------
[?]忘各位能帮助解决,谢谢!  

解决方案 »

  1.   

    大家执行时,点击form1中create page 按钮,多次,就可发现问题
      

  2.   

    将隐藏控件的代码放在OnCreate事件里面,或者在ToolButton点击事件里加一句Form.Show
      

  3.   

    liangqingzhi(老之) :请问;为何原来的操作就不可以呢?
      

  4.   

    后来看了一下,OnShow里的其实是执行的,但被改了回来。问题是在PageControl1.ActivePage := Sheet;这一句,要放在Form. Visible := True;前面。
      

  5.   

    liangqingzhi(老之) :
    其实属性值已经设置成功了,只是显示的问题了
      

  6.   

    没想过要这么作, 另一种方法也可以把 Form 作为 PageControl 的 Sheet Form := TForm2.Create (Application);
     Form.ManualDock(PageControl1, nil, alClient);
     Form.Visible := True; 这句完全等同于 Form.Show这样作完后 
    Sheet.Caption = Form.Caption 代码激活某叶可以用这个