public void SetActivePage(WizardPage newPage) { WizardPage oldActivePage = _activePage; // If this page isn't in the Controls collection, add it. // This is what causes the Load event, so we defer // it as late as possible. if (!pagePanel.Controls.Contains(newPage)) pagePanel.Controls.Add(newPage); // Show this page. newPage.Visible = true; _activePage = newPage; CancelEventArgs e = new CancelEventArgs(); newPage.OnSetActive(e); if (e.Cancel) { newPage.Visible = false; _activePage = oldActivePage; } // Hide all of the other pages. foreach (WizardPage page in _pages) { if (page != _activePage) page.Visible = false; } }