开发者

How can I set the current page of a TPageControl?

I am using a pagecontrol component开发者_如何学编程 and I need to add a button and click it to go to a specified page.

How can I do this please?


Add a button to the form and write an OnClick event handler like this:

procedure TMyForm.Button1Click(Sender: TObject);
begin
  PageControl1.ActivePage := TabSheet1;
end;


You can use ActivePageIndex:

procedure TForm1.Button1Click(Sender: TObject);
begin
  PageControl1.ActivePageIndex := 0;
end;


Can I just add that you cannot set the active page within the OnChange event (I tried for ages!). Any checks that are needed must be done within the OnChanging event and then set the Allowchange var to true or false accordingly:

procedure Tfrm_AspireParams.PC_OptionsChanging(Sender: TObject;
  var AllowChange: Boolean);
begin
 AllowChange := true;
 if fActivated then
 begin
   if BBtn_Timesheets_Save.Enabled then  // They have not saved changes on this tab.
   begin
     messagedlg('Please save the page first', mtInformation, [mbOK], 0);
     AllowChange := False;
   end;
 end;

end;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜