原創(chuàng)|使用教程|編輯:龔雪|2021-02-22 09:58:10.950|閱讀 252 次
概述:本文主要為大家演示在使用Splash Screen Manager時(shí),如何在覆蓋表單上顯示自定義按鈕。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
注意:GitHub上提供了完整的示例項(xiàng)目,網(wǎng)址為:
是一個(gè)半透明的啟動(dòng)屏幕,他在后臺線程中運(yùn)行并覆蓋控件或表單來防止對其進(jìn)行訪問,Overlay Form僅包含一個(gè)等待指示器。
本示例演示如何顯示:
本示例使您可以更改標(biāo)簽文本、按鈕字形以及單擊按鈕時(shí)執(zhí)行的操作。
您可以按以下方式自定義Overlay Form圖形:
本示例使用OverlayImagePainter和OverlayTextPainter對象(OverlayWindowPainterBase后代),它們實(shí)現(xiàn)了圖像和文本的繪制邏輯,并且您可以使用它們的屬性來自定義圖像和文本。
OverlayImagePainter對象在Overlay Form的頂部中心繪制一個(gè)自定義圖像,并處理該圖像上的單擊。 您可以指定以下屬性:
OverlayTextPainter對象在等待指示器下方繪制一個(gè)自定義標(biāo)簽,您可以指定以下屬性:
OverlayWindowCompositePainter對象在OverlayImagePainter和OverlayTextPainter對象中組成繪圖邏輯,該復(fù)合繪制器作為參數(shù)傳遞給SplashScreenManager.ShowOverlayForm方法。
顯示Overlay Form時(shí)執(zhí)行的操作是使用.Net Framework類庫(任務(wù)并行庫(TPL))中可用的可取消任務(wù)來實(shí)現(xiàn)的。
按鈕圖像顯示在Overlay Form的頂部中央,標(biāo)簽顯示在等待指示器下方,您可以重寫以下方法來指定其位置:
每次需要重新繪制疊加表單時(shí)(例如,當(dāng)用戶調(diào)整重疊控件的大小時(shí)),都會(huì)調(diào)用這些方法,drawArgs方法參數(shù)包含繪制覆蓋圖所需的信息。本示例使用以下屬性:
下面的代碼段顯示了如何更新當(dāng)前示例來在自定義位置顯示按鈕和標(biāo)簽。
C#
using DevExpress.Utils.Extensions; using DevExpress.XtraSplashScreen; class OverlayImagePainterEx : OverlayImagePainter { public OverlayImagePainterEx(Image image, Image hoverImage = null, Action clickAction = null) : base(image, hoverImage, clickAction) { } protected override Rectangle CalcImageBounds(OverlayLayeredWindowObjectInfoArgs drawArgs) { int indent = 10; return Image.Size.AlignWith(drawArgs.Bounds).WithY(indent).WithX(drawArgs.Bounds.Width - Image.Height - indent); } } class OverlayTextPainterEx: OverlayTextPainter { protected override Rectangle CalcTextBounds(OverlayLayeredWindowObjectInfoArgs drawArgs) { Size textSz = CalcTextSize(drawArgs); return textSz.AlignWith(drawArgs.Bounds).WithY(drawArgs.ImageBounds.Top - textSz.Height); } } public partial class Form1 : RibbonForm { //.. OverlayTextPainter overlayLabel; OverlayImagePainter overlayButton; public Form1() { //... this.overlayLabel = new OverlayTextPainterEx(); this.overlayButton = new OverlayImagePainterEx(buttonImage, hotButtonImage, OnCancelButtonClick); InitializeComponent(); } async void OnRunTaskItemClick(object sender, ItemClickEventArgs e) { //... //Pass the created descendants to the SplashScreenManager.ShowOverlayForm method. IOverlaySplashScreenHandle overlayHandle = SplashScreenManager.ShowOverlayForm(contentPanel, customPainter: new OverlayWindowCompositePainter(overlayLabel, overlayButton)); //... } }
VB.NET
Imports DevExpress.XtraSplashScreen Imports DevExpress.Utils.Extensions Friend Class OverlayImagePainterEx Inherits OverlayImagePainter Public Sub New(ByVal image As Image, Optional ByVal hoverImage As Image = Nothing, Optional ByVal clickAction As Action = Nothing) MyBase.New(image, hoverImage, clickAction) End Sub Protected Overrides Function CalcImageBounds(ByVal drawArgs As OverlayLayeredWindowObjectInfoArgs) As Rectangle Dim indent As Integer = 10 Return Image.Size.AlignWith(drawArgs.Bounds).WithY(indent).WithX(drawArgs.Bounds.Width - Image.Height - indent) End Function End Class Friend Class OverlayTextPainterEx Inherits OverlayTextPainter Protected Overrides Function CalcTextBounds(ByVal drawArgs As OverlayLayeredWindowObjectInfoArgs) As Rectangle Dim textSz As Size = CalcTextSize(drawArgs) Return textSz.AlignWith(drawArgs.Bounds).WithY(drawArgs.ImageBounds.Top - textSz.Height) End Function End Class Partial Public Class Form1 Inherits RibbonForm '... Private overlayLabel As OverlayTextPainter Private overlayButton As OverlayImagePainter Public Sub New() '... Me.overlayLabel = New OverlayTextPainterEx() Me.overlayButton = New OverlayImagePainterEx(buttonImage, hotButtonImage, AddressOf OnCancelButtonClick) InitializeComponent() End Sub Private Async Sub OnRunTaskItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs) Handles biRunTask.ItemClick '... 'Pass the created descendants to the SplashScreenManager.ShowOverlayForm method. Dim overlayHandle As IOverlaySplashScreenHandle = SplashScreenManager.ShowOverlayForm(contentPanel, customPainter:=New OverlayWindowCompositePainter(overlayLabel, overlayButton)) '... End Sub
下圖說明了生成的布局。
DevExpress技術(shù)交流群3:700924826 歡迎一起進(jìn)群討論
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都網(wǎng)