How can I set the current page of a TPageControl?

tpagecontrol add page
delphi pagecontrol create tab sheet
delphi add frame to pagecontrol
delphi open form in pagecontrol

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;

TPageControl.ActivePage Property, The user selects a page by clicking the mouse on its tab. Set ActivePage to bring a page to the foreground. Only one page can be active at a time. To change the ActivePage to the page that precedes or follows the active page, use the SelectNextPage method. TPageControl changing order of pages. 3. Changing page in TPageControl. 4. changing page order in TPageControl? 5. Visual page / Active page. 6. Color of active tab in TPageControl. 7. Delphi2-Get active TTabSheet of TPageControl. 8. Changing InsertSQL closes an active IBDataSet - How can you dynamically change the insertSQL statement. 9.

You can use ActivePageIndex:

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

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 Can I just add that you cannot set the active page within the OnChange event (I� Use SelectNextPage to select the page next to the currently active page. If the GoForward parameter is true, SelectNextPage selects the first page after ActivePage; if GoForward is false, SelectNextPage selects the first page previous to ActivePage.

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;

TPageControl - Lazarus wiki, Right-click on a TPageControl to show its context menu, and use 'Add Page' to create a new page. The current (active) page is accessible through the ActivePage property. TPageControl displays multiple overlapping pages that are TTabSheet objects. The user selects a page by clicking the page's tab that appears at the top of the control. To add a new page to a TPageControl object at design time, right-click the TPageControl object and choose New Page. To create a tabbed control that uses only a single body portion (page), use TTabControl instead.

Multiple-Page Forms :: Chapter 6: Building the User Interface :: Part I , The PageControl component has tabs on one side and multiple pages (similar to panels) Then the number of the new tab is used to change the active tab: Each page is a TTabSheet object. To locate a page in the page control by its position relative to another page, use the FindNextPage method. Note: Pages is a read-only property. To add a tab sheet to a page control at design time, right click and select New Page.

TPageControl, ActivePage - the currently selected active page ( TTabSheet ). property The set of anchor definitions for this control. property BorderSpacing:� An OnChanging event handler can also be used to save information about the current state of the tab control before it is changed by a new tab selection. Note: The event is not called if you change the active page in code, for example, by setting the value of TPageControl.

How to Hide the Tabs of the TPageControl Delphi Control, To programmatically set the active page, use the SelectNextPage method: //Hide PageControl Tabs var page : integer; begin for page := 0 to� Use ActivePageIndex to get or set the active page by index rather than by object. The value of ActivePageIndex identifies a page in the Pages property array. Changing the value of ActivePageIndex changes the ActivePage property, and vice versa. If there is no active page, reading ActivePageIndex gives a value of -1.

Comments
  • @Satch3000, good suggestion but note that this will not trigger an OnPageChange event for the PageControl, if you want that to happen you'll need to call that event in your Button1Click explicitly.
  • This is equivalent to using ActivePage, the two properties are synonymous
  • I would still prefer setting ActivePage, because the index of a page is variable. Or at least: has that ability. The reference to a page on the other hand will always stay the same. And most likely will the code be more readable with a self-descriptive variable name than with a meaningless digit.
  • I think it depends on situation. Many times I used ActivePageIndex set to 0 on formShow to be sure that first one will be visible on start. After rearenging tabsheets code its still ok.
  • Well, that's hardly a situation, but just a knack to reset the changes you've made in the designer. ;) Good tip though! +1