クイックスタート
A Wizard in a Few Lines
The same API in Delphi, C++ Builder and C#: add the pages, mark one as optional, and validate before the user leaves the Account page.
procedure TMainForm.CreateWizard;
var
oPage: TsgcVCLWizardPage;
begin
// the wizard fills the form: stepper on the left, buttons at the bottom
FWizard := TsgcVCLWizard.Create(Self);
FWizard.Parent := Self;
FWizard.Align := alClient;
FWizard.StepperPosition := wspLeft;
FWizard.Theme := utDark;
FWizard.NextCaption := 'Continue';
FWizard.FinishCaption := 'Create account';
// every page is a step of the stepper
oPage := FWizard.AddPage('Welcome');
oPage.Description := 'Start here';
oPage := FWizard.AddPage('Account');
oPage.Description := 'Your details';
FName := TEdit.Create(Self);
FName.Parent := oPage;
FName.SetBounds(24, 24, 240, 24);
// an optional page the user can skip: Next and Back jump over it
FOptions := FWizard.AddPage('Options');
FOptions.Description := 'Optional';
FOptions.Skip := True;
oPage := FWizard.AddPage('Done');
oPage.Description := 'Summary';
FWizard.ActivePageIndex := 0;
FWizard.OnBeforePageChange := WizardBeforePageChange;
FWizard.OnFinish := WizardFinish;
end;
procedure TMainForm.WizardBeforePageChange(Sender: TObject;
aFromIndex, aToIndex: Integer; var aAllow: Boolean);
begin
// veto: leaving Account forwards needs a name
if (aFromIndex = 1) and (aToIndex > aFromIndex) then
aAllow := Trim(FName.Text) <> '';
end;
procedure TMainForm.WizardFinish(Sender: TObject);
begin
ShowMessage('Welcome, ' + FName.Text);
end;
#include <vcl.h>
#include <Vcl.StdCtrls.hpp>
#include "sgcUICore_Theme.hpp"
#include "sgcWizard_Model.hpp"
#include "sgcWizard_VCL.hpp"
class TWizardHandler : public TObject
{
public:
TEdit *Name;
void __fastcall BeforePageChange(TObject *Sender, int aFromIndex,
int aToIndex, bool &aAllow);
void __fastcall Finish(TObject *Sender);
};
void __fastcall TWizardHandler::BeforePageChange(TObject *Sender,
int aFromIndex, int aToIndex, bool &aAllow)
{
// veto: leaving Account forwards needs a name
if ((aFromIndex == 1) && (aToIndex > aFromIndex))
aAllow = !Name->Text.Trim().IsEmpty();
}
void __fastcall TWizardHandler::Finish(TObject *Sender)
{
ShowMessage("Welcome, " + Name->Text);
}
void __fastcall CreateWizard(TForm *Form, TWizardHandler *Handler)
{
// the wizard fills the form: stepper on the left, buttons at the bottom
TsgcVCLWizard *Wizard = new TsgcVCLWizard(Form);
Wizard->Parent = Form;
Wizard->Align = alClient;
Wizard->StepperPosition = wspLeft;
Wizard->Theme = utDark;
Wizard->NextCaption = "Continue";
Wizard->FinishCaption = "Create account";
// every page is a step of the stepper
TsgcVCLWizardPage *Page = Wizard->AddPage("Welcome");
Page->Description = "Start here";
Page = Wizard->AddPage("Account");
Page->Description = "Your details";
Handler->Name = new TEdit(Form);
Handler->Name->Parent = Page;
Handler->Name->SetBounds(24, 24, 240, 24);
// an optional page the user can skip: Next and Back jump over it
Page = Wizard->AddPage("Options");
Page->Description = "Optional";
Page->Skip = true;
Page = Wizard->AddPage("Done");
Page->Description = "Summary";
Wizard->ActivePageIndex = 0;
Wizard->OnBeforePageChange = Handler->BeforePageChange;
Wizard->OnFinish = Handler->Finish;
}
using System;
using System.Windows.Forms;
using esegece.sgcUICore;
using esegece.sgcWizard;
internal class MainForm : Form
{
private readonly TsgcWinFormsWizard Wizard = new TsgcWinFormsWizard();
private readonly TextBox txtName = new TextBox();
public MainForm()
{
// the wizard fills the form: stepper on the left, buttons at the bottom
Wizard.Dock = DockStyle.Fill;
Wizard.StepperPosition = TsgcWizardStepperPosition.wspLeft;
Wizard.Theme = TsgcUITheme.utDark;
Wizard.NextCaption = "Continue";
Wizard.FinishCaption = "Create account";
Controls.Add(Wizard);
// every page is a step of the stepper
TsgcWinFormsWizardPage oPage = Wizard.AddPage("Welcome");
oPage.Description = "Start here";
oPage = Wizard.AddPage("Account");
oPage.Description = "Your details";
txtName.SetBounds(24, 24, 240, 24);
oPage.Controls.Add(txtName);
// an optional page the user can skip: Next and Back jump over it
oPage = Wizard.AddPage("Options");
oPage.Description = "Optional";
oPage.Skip = true;
oPage = Wizard.AddPage("Done");
oPage.Description = "Summary";
Wizard.ActivePageIndex = 0;
Wizard.OnBeforePageChange = WizardBeforePageChange;
Wizard.OnFinish = sender => MessageBox.Show("Welcome, " + txtName.Text);
}
private void WizardBeforePageChange(object sender, int aFromIndex, int aToIndex, ref bool aAllow)
{
// veto: leaving Account forwards needs a name
if (aFromIndex == 1 && aToIndex > aFromIndex)
aAllow = txtName.Text.Trim() != "";
}
}
dotnet add package esegece.sgcWizard.WinForms