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