回 帖 发 新 帖 刷新版面

主题:关于窗体的问题

我想做一个,把主窗口分为左右两部分,左边窗体有5个按钮,分别控制右边窗体的显示与隐藏,比如:
      按下左边窗体的按钮1,右边显示界面1;
      按下左边窗体的按钮2,右边显示界面2;
      .........
      按下左边窗体的按钮5,右边显示界面5;
请问如何实现?

回复列表 (共8个回复)

沙发

我也想知道

板凳

用TNoteBook控件,在控件表WIN3.1下。

3 楼

你可以在窗体中放两个GroupBox控件,分别左右放置,再把相应的按钮分别放入两个GroupBox中,最后,你的事件只要触发这两个GroupBox显示或是隐藏即可

4 楼


你可以把右边要显示的界面分别建成一个单独的窗体。
然后再分别写用于显示窗体的函数。
不过窗体显示时要设置他的父窗体为先前窗体上的一具容器。
这样窗体显示时就成为先前那窗体的右边的一部分了。
我现在用的就是这样的方法。不知符不符合你的要求。

5 楼


谢谢大家的帮忙!
能说的具体一些吗?或者有实例也可以

6 楼

用TNoteBook控件,可以生成多页。点击某个按钮,显示其某一页就行了。

你可以试验一下,遇到问题再讨论。

7 楼

假设窗体是用Panel分为左右两部分。要在from1窗体的右边显示form2窗体。
procedure Tform1.CreateNewfrm;
var
  frm: Tform2;
begin
   try
     FreeAndNil(frmpub);
     frm:= Tform2.Create(nil);
     frmpub:= frm;
     frm.Align:= alClient;  
     frm.Parent:= Panel;   在这里Pnael为form1窗体的右边部分。
     frm.DBGridTrainStuff.Align:= alClient;
     frm.Update;
     frm.BorderStyle:= bsNone;
     frm.Show;
   Finally
   end;
end;

上面的函数写在form1窗体上,然后再调用这个函数来显示form2窗体。
要在{ Public declarations }下面定义一个frmpub: TWinControl;变量。

8 楼

unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

uses Unit2, Unit3;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if CurrentFrame<>nil then
    CurrentFrame.Free;
  CurrentFrame:=TFrame1.Create(Self);
  CurrentFrame.Parent:=Panel1;
  CurrentFrame.Align:=alClient;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if CurrentFrame<>nil then
    CurrentFrame.Free;
  CurrentFrame:=TFrame2.Create(Self);
  CurrentFrame.Parent:=Panel1;
  CurrentFrame.Align:=alClient;
end;

end.


unit Unit2;

interface

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

type
  TFrame1 = class(TFrame)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

implementation


{$R *.dfm}

end.

unit Unit3;

interface

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

type
  TFrame2 = class(TFrame)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

implementation

{$R *.dfm}

end.

我来回复

您尚未登录,请登录后再回复。点此登录或注册