翻譯|使用教程|編輯:龔雪|2021-01-08 11:51:15.563|閱讀 502 次
概述:本文將為大家介紹如何在Telerik UI for WinForms套件中使用新的RadTaskDialog控件,以多種方式幫助您的用戶。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
在Telerik UI for WinForms的R3 2020版本中,套件中添加了新的RadTaskDialog組件。 任務對話框是一個小窗口,它向用戶顯示信息并提示他們進行響應。 與常規消息框相比,任務對話框具有許多配置選項,可以顯示其他UI元素(如單選按鈕和進度條),并支持事件處理。
RadTaskDialog是Windows對話框和新發布的.NET 5的TaskDialog可替代選擇,該對話框是一個窗口,允許用戶執行命令、向用戶提問、為用戶提供信息或指示進度、正在進行的任務。RadTaskDialog代表標準System.Windows.Forms.MessageBox和RadMessageBox的擴展版本,與常規消息框相比,它可以顯示其他控件,例如進度條,并支持事件處理。
它有一個包含所有必要用戶信息的主要元素 - RadTaskDialogPage,RadTaskDialogPage公開了一些有用的屬性,這些屬性使您可以僅用幾行代碼來設置整個對話框:
在描述了對話框的主要功能之后,就該展示一些用例了。 但是在此之前,我們需要澄清兩件重要的事情:
這是PDF文件移動期間的示例案例,用戶必須決定是替換原始文件,取消還是保留兩個文件。
這是代碼,大多數行用于配置命令鏈接按鈕:
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 }
另一個有趣的情況是您需要創建一個多頁對話框。 要切換頁面,您只需要調用當前顯示的RadTaskDialogPage的Navigate方法。
這是打印機安裝示例:
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++; }; };
最后,技術團隊還組件了三組不同的矢量圖標:漸變、平面和白色:
我們添加了三種不同的方法,這些方法根據內部需求返回不同的格式和大小。 要訪問這些圖像,可以使用以下代碼:
// 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);
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都網