CodePudding user response:
According to different conditions to prevent tabsheet switchingCodePudding user response:
Procedure TForm1. PageControl1Changing (Sender: TObject;Var AllowChange: Boolean);
The begin
If (your judgment conditions) then
AllowChange:=True
The else
AllowChange:=Flase;
end;
CodePudding user response:
1, set up a global variableVar
OnChange: Boolean;
2, OnChenging eventIf onChange then
The begin
AllowChange:=True;//open
End
The else begin
AllowChange:=False;//lock
end;
3, press the button event, whether set into the pages and lock the Page
(1) PageControl1. ActivePageIndex:=1;//into the surface 2
OnChange:=False;//lock the Page
(2) the OnChange:=True;//open the Page
PageControl1. ActivePageIndex:=0;//into the surface 1
[Delphi=code]
The unit Unit1;
Interface
USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls ComCtrls;
Type
TForm1=class (TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
TabSheet4: TTabSheet;
For: TButton;
Button2: TButton;
Procedure Button1Click (Sender: TObject);
Procedure PageControl1Changing (Sender: TObject;
Var AllowChange: Boolean);
Procedure Button2Click (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
end;
Var
Form1: TForm1;
OnChange: Boolean;
Implementation
{$R *. DFM}
Procedure TForm1. Button1Click (Sender: TObject);
The begin
OnChange:=True;//open the Page
PageControl1. ActivePageIndex:=0;//into the surface 1
end;
Procedure TForm1. PageControl1Changing (Sender: TObject;
Var AllowChange: Boolean);
The begin
If onChange then
The begin
AllowChange:=True;//open
End
The else begin
AllowChange:=False;//lock
end;
end;
Procedure TForm1. Button2Click (Sender: TObject);
The begin
PageControl1. ActivePageIndex:=1;//into the surface 2
OnChange:=False;//lock the Page
end;
End.
[/code]
CodePudding user response:
unit Unit1;
Interface
USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls ComCtrls;
Type
TForm1=class (TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
TabSheet4: TTabSheet;
For: TButton;
Button2: TButton;
Procedure Button1Click (Sender: TObject);
Procedure PageControl1Changing (Sender: TObject;
Var AllowChange: Boolean);
Procedure Button2Click (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
end;
Var
Form1: TForm1;
OnChange: Boolean;
Implementation
{$R *. DFM}
Procedure TForm1. Button1Click (Sender: TObject);
The begin
OnChange:=True;//open the Page
PageControl1. ActivePageIndex:=0;//into the surface 1
end;
Procedure TForm1. PageControl1Changing (Sender: TObject;
Var AllowChange: Boolean);
The begin
If onChange then
The begin
AllowChange:=True;//open
End
The else begin
AllowChange:=False;//lock
end;
end;
Procedure TForm1. Button2Click (Sender: TObject);
The begin
PageControl1. ActivePageIndex:=1;//into the surface 2
OnChange:=False;//lock the Page
end;
End.