HeaderPane
Main
Hide
Share Link
Print

Task Dialog Navigation

SftTaskDialogPage.Navigate replaces the page shown in a dialog with another page, without closing the dialog, for example to show the progress of an operation the user just started and then its result. Since the buttons and elements of a page cannot change while it is shown, navigation is also how a dialog changes them. SftTaskDialog.ShowDialog returns when the dialog closes, with the button that closed it, which can be a button of any page that was shown.

MemberDescription
SftTaskDialogPage.NavigateReplaces this page with another page in the dialog that shows this page.
SftTaskDialogPage.CreatedOccurs when the page appears in the dialog, when the dialog opens or after a navigation.
SftTaskDialogPage.DestroyedOccurs when the page leaves the dialog, because the dialog closes or another page replaces it.
SftTaskDialogPage.HelpRequestOccurs when the user asks for help with F1 or the Help button.

A navigation raises SftTaskDialogPage.Destroyed of the current page at once, then SftTaskDialogPage.Created of the new page when it has appeared, after the current event. The new page belongs to the dialog at once (SftTaskDialogPage.BoundDialog), but its buttons cannot be clicked with SftTaskDialogButton.PerformClick and its radio buttons cannot be checked before it has appeared. A Click handler of a button can navigate: the dialog then stays open, also for a button whose SftTaskDialogButton.AllowCloseDialog is True.

C#

SftTaskDialogPage confirm = new SftTaskDialogPage {
    Caption = "Archive",
    Heading = "Archive the orders of 2025?",
    Text = "The 1,284 orders are moved to the archive file.",
};
SftTaskDialogButton start = new SftTaskDialogButton("&Archive");
confirm.Buttons.Add(start);
confirm.Buttons.Add(SftTaskDialogButton.Cancel);

SftTaskDialogPage progress = new SftTaskDialogPage {
    Caption = "Archive",
    Heading = "Archiving the orders...",
    ProgressBar = new SftTaskDialogProgressBar(),
};
SftTaskDialogButton close = SftTaskDialogButton.Close;
close.Enabled = false;
progress.Buttons.Add(close);

System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer { Interval = 50 };
timer.Tick += (s, e) => {
    progress.ProgressBar.Value += 2;
    if (progress.ProgressBar.Value >= 100) {
        timer.Stop();
        progress.Heading = "The orders have been archived";
        close.Enabled = true;
    }
};
progress.Created += (s, e) => timer.Start();
progress.Destroyed += (s, e) => timer.Dispose();
start.Click += (s, e) => confirm.Navigate(progress);

SftTaskDialog.ShowDialog(this, confirm);

VB

Dim confirm As New SftTaskDialogPage With {
    .Caption = "Archive",
    .Heading = "Archive the orders of 2025?",
    .Text = "The 1,284 orders are moved to the archive file."
}
Dim start As New SftTaskDialogButton("&Archive")
confirm.Buttons.Add(start)
confirm.Buttons.Add(SftTaskDialogButton.Cancel)

Dim progress As New SftTaskDialogPage With {
    .Caption = "Archive",
    .Heading = "Archiving the orders...",
    .ProgressBar = New SftTaskDialogProgressBar()
}
Dim closeButton As SftTaskDialogButton = SftTaskDialogButton.Close
closeButton.Enabled = False
progress.Buttons.Add(closeButton)

Dim timer As New Timer With {.Interval = 50}
AddHandler timer.Tick, Sub(s, e)
    progress.ProgressBar.Value += 2
    If progress.ProgressBar.Value >= 100 Then
        timer.Stop()
        progress.Heading = "The orders have been archived"
        closeButton.Enabled = True
    End If
End Sub
AddHandler progress.Created, Sub(s, e) timer.Start()
AddHandler progress.Destroyed, Sub(s, e) timer.Dispose()
AddHandler start.Click, Sub(s, e) confirm.Navigate(progress)

SftTaskDialog.ShowDialog(Me, confirm)

Navigate is called on the page the dialog shows. It throws an InvalidOperationException on a page that is not shown in a dialog, in a Destroyed handler or a radio button's CheckedChanged handler, once the dialog has started closing, and when the new page cannot be shown (see Task Dialog).