Telerik UI for WinForms-RadTaskDialog control use method full solution

Telerik UI for WinForms latest version download

In the R3 2020 version of Telerik UI for WinForms , a new RadTaskDialog component has been added to the kit. The task dialog is a small window that displays information to users and prompts them to respond. Compared with regular message boxes, task dialogs have many configuration options, can display other UI elements (such as radio buttons and progress bars), and support event handling.

Telerik UI for WinForms tutorial

Overview

RadTaskDialog is an alternative to the Windows dialog box and the newly released TaskDialog of .NET 5. The dialog box is a window that allows users to execute commands, ask users questions, provide users with information or indicate progress or tasks in progress. RadTaskDialog represents an extended version of the standard System.Windows.Forms.MessageBox and RadMessageBox. Compared with the regular message box, it can display other controls, such as a progress bar, and supports event handling.

Features

  • Auto-Size: The size of the window is based on the content added to the page.
  • Pagination: Provides navigation to a new page (by rebuilding the dialog from the current properties). The task dialog can act as a small wizard with multiple pages. Microsoft recommends using no more than three pages.
  • Supported elements: The task dialog supports various predefined elements (such as flat buttons, regular buttons, progress bars, waiting bars, radio buttons, check boxes, expander buttons, expander areas, and footers). These elements Can be assigned and arranged automatically without writing any layout logic.
  • Icon: In addition to the standard icons for errors, warnings, and information, the task dialog also has green, yellow, red, gray or blue bars on the entire title/title background. In addition, custom icons and images are also supported out of the box.
  • Modal and non-modal: You can use ShowDialog or Show methods to display modal or non-modal.
  • Localization: Localization of each predefined string.
  • Theme: More than 25 predefined themes.
  • Customization: RadTaskDialog can be constructed according to the specific requirements you need to meet, and allows to add or delete any element and customize any predefined element.

It has a main element that contains all necessary user information-RadTaskDialogPage. RadTaskDialogPage exposes some useful properties that allow you to set up the entire dialog with just a few lines of code:

  • Caption: The text in the title bar of RadTaskDialogForm when this page is displayed.
  • Icon: with vector images, and can display green, red, yellow, blue or gray bars as the title background.
  • Heading: The header/title of the page.
  • Text: Display descriptive information about the purpose of the dialog box.
  • ProgressBar: Used to indicate definite or uncertain progress.
  • RadioButtons: A collection of radio buttons, allowing users to choose from different options.
  • ContentAreaButtons: A collection of flat buttons displayed at the top of the dialog box. These buttons are flat and have three main elements: icon, title, and description text.
  • Expander: Define detailed information/descriptive text, which can be collapsed by the toggle button.
  • Verification: The checkbox can be used to receive user confirmation.
  • CommandAreaButtons: A collection of regular buttons displayed at the bottom of the page.
  • Footnote: Provides optional additional instructions and help, usually for inexperienced users.

usage

After describing the main functions of the dialog, it's time to show some use cases. But before that, we need to clarify two important things:

  • RadTaskDialog requires RadTaskDialogPage as the parameter to be displayed.
  • RadTaskDialog does not return System.Windows.Forms.DailogResult (such as MessageBox), but returns an instance of the button clicked by the user.

This is a sample case during the PDF file move, the user must decide whether to replace the original file, cancel or keep both files.

Telerik UI for WinForms tutorial

This is the code, most of the lines are used to configure the command link button:

 

RadTaskDialogPage page = new RadTaskDialogPage()
{
SizeToContent = true,
Icon = RadTaskDialogIcon.ShieldBlueBar,
Caption = "Move File",
Heading = "There is already a file with the same name in this location.",
Text = "Click the file you want to keep",
CommandAreaButtons = {
RadTaskDialogButton.Cancel
},
AllowCancel = true,
UseWideContentArea = true
};

RadSvgImage pdfIcon = RadSvgImage.FromFile(@"..\..\Resources\file-pdf.svg");
pdfIcon.Size = new Size(50, 50);
RadTaskDialogCommandLinkButton moveButton = new RadTaskDialogCommandLinkButton(
"Move and Replace",
@"Replace the file in the destination folder with the file you are moving:" + Environment.NewLine +
"document.pdf" + Environment.NewLine + "Size: 275 KB" + Environment.NewLine + "Date Modified: 11.11.2018 12:45");
moveButton.SvgImage = pdfIcon;
page.ContentAreaButtons.Add(moveButton);

RadTaskDialogCommandLinkButton dontMoveButton = new RadTaskDialogCommandLinkButton(
"Don't move",
@"Replace the file in the destination folder with the file you are moving:" + Environment.NewLine +
"document.pdf" + Environment.NewLine + "Size: 275 KB" + Environment.NewLine + "Date Modified: 11.11.2018 12:45");
dontMoveButton.SvgImage = (RadSvgImage)pdfIcon.Clone();
page.ContentAreaButtons.Add(dontMoveButton);

RadTaskDialogCommandLinkButton keepBothButton = new RadTaskDialogCommandLinkButton(
"Move, but keep both files",
"The file you are moving will be renamed 'document(2).pdf'");
page.ContentAreaButtons.Add(keepBothButton);

RadTaskDialogButton clickedButton = RadTaskDialog.ShowDialog(page);
if (clickedButton == null || clickedButton == RadTaskDialogButton.Cancel)
{
// the user cancelled the action
}
else if (clickedButton == moveButton)
{
// move and replace
}
else if (clickedButton == dontMoveButton)
{
// do not move
}
else if (clickedButton == keepBothButton)
{
// move and keep both files
}

 

Another interesting situation is that you need to create a multi-page dialog. To switch pages, you only need to call the Navigate method of the RadTaskDialogPage currently displayed.

This is a printer installation example:

Telerik UI for WinForms tutorial

 

RadTaskDialogButton initialButtonYes = RadTaskDialogButton.Continue;
initialButtonYes.Enabled = false;
initialButtonYes.AllowCloseDialog = false;

RadTaskDialogPage initialPage = new RadTaskDialogPage()
{
Caption = "Hardware Installation",
Heading = "Installation Warning",
Text = "The software you are installing for this hardware:\nPrinters\nhas not passed Windows Logo testing to verify its compatibility with Windows",
Icon = RadTaskDialogIcon.ShieldWarningYellowBar,
AllowCancel = true,

Verification = new RadTaskDialogVerificationCheckBox()
{
Text = "Install anyway"
},

CommandAreaButtons =
{
initialButtonYes,
RadTaskDialogButton.Cancel
},
DefaultButton = RadTaskDialogButton.Cancel
};

RadTaskDialogPage inProgressPage = new RadTaskDialogPage()
{
Caption = "Hardware Installation",
Heading = "Installation in progress...",
Text = "Please wait while the installation is in progress.",
Icon = RadTaskDialogIcon.Information,

ProgressBar = new RadTaskDialogProgressBar()
{
State = RadTaskDialogProgressBarState.Marquee
},

Expander = new RadTaskDialogExpander()
{
Text = "Initializing...",
Position = RadTaskDialogExpanderPosition.AfterFootnote
},

CommandAreaButtons =
{
RadTaskDialogButton.Cancel
}
};

RadTaskDialogPage finishedPage = new RadTaskDialogPage()
{
Caption = "Hardware Installation",
Heading = "Success!",
Text = "The Printer installation completed successfully.",
Icon = RadTaskDialogIcon.ShieldSuccessGreenBar,
CommandAreaButtons =
{
new RadTaskDialogButton("Finish")
}
};

RadTaskDialogVerificationCheckBox checkBox = initialPage.Verification;
checkBox.CheckedChanged += (sender, e) =>
{
initialButtonYes.Enabled = checkBox.Checked;
};

initialButtonYes.Click += (sender, e) =>
{
initialPage.Navigate(inProgressPage);
};

inProgressPage.Created += delegate (object s, EventArgs e)
{
RadTaskDialogProgressBar progressBar = inProgressPage.ProgressBar;
Timer timer = new Timer();
timer.Interval = 2800;
int progressValue = 0;
timer.Start();
timer.Tick += delegate (object sender, EventArgs args)
{
timer.Interval = 40;
if (progressBar.State == RadTaskDialogProgressBarState.Marquee)
{
progressBar.State = RadTaskDialogProgressBarState.Normal;
}

progressBar.Value = progressValue;
inProgressPage.Expander.Text = string.Format("Installation Progress: {0} %", progressValue);
if (progressValue == 100)
{
timer.Stop();
timer.Dispose();
inProgressPage.Navigate(finishedPage);
}

progressValue++;
};
};

 

Finally, the technical team also assembled three different sets of vector icons: gradient, flat and white:

Telerik UI for WinForms tutorial

We have added three different methods, which return different formats and sizes according to internal requirements. To access these images, you can use the following code:

// Returns a vector image
RadSvgImage svgIcon = RadTaskDialogIcon.GetSvgImage(RadTaskDialogIconImage.FlatShieldQuestion);

// Returns a raster image with size 16x16px
Image smallIcon = RadTaskDialogIcon.GetSmallImage(RadTaskDialogIconImage.FlatShieldQuestion);

// Returns a raster image with size 26x26px
Image largeIcon = RadTaskDialogIcon.GetLargeImage(RadTaskDialogIconImage.FlatShieldQuestion);

For the latest news of Kendo UI, please follow Telerik Chinese website!

Guess you like

Origin blog.csdn.net/AABBbaby/article/details/112461851