原創|使用教程|編輯:龔雪|2021-02-22 09:58:10.950|閱讀 252 次
概述:本文主要為大家演示在使用Splash Screen Manager時,如何在覆蓋表單上顯示自定義按鈕。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
注意:GitHub上提供了完整的示例項目,網址為:
是一個半透明的啟動屏幕,他在后臺線程中運行并覆蓋控件或表單來防止對其進行訪問,Overlay Form僅包含一個等待指示器。
本示例演示如何顯示:
本示例使您可以更改標簽文本、按鈕字形以及單擊按鈕時執行的操作。
您可以按以下方式自定義Overlay Form圖形:
本示例使用OverlayImagePainter和OverlayTextPainter對象(OverlayWindowPainterBase后代),它們實現了圖像和文本的繪制邏輯,并且您可以使用它們的屬性來自定義圖像和文本。
OverlayImagePainter對象在Overlay Form的頂部中心繪制一個自定義圖像,并處理該圖像上的單擊。 您可以指定以下屬性:
OverlayTextPainter對象在等待指示器下方繪制一個自定義標簽,您可以指定以下屬性:
OverlayWindowCompositePainter對象在OverlayImagePainter和OverlayTextPainter對象中組成繪圖邏輯,該復合繪制器作為參數傳遞給SplashScreenManager.ShowOverlayForm方法。
顯示Overlay Form時執行的操作是使用.Net Framework類庫(任務并行庫(TPL))中可用的可取消任務來實現的。
按鈕圖像顯示在Overlay Form的頂部中央,標簽顯示在等待指示器下方,您可以重寫以下方法來指定其位置:
每次需要重新繪制疊加表單時(例如,當用戶調整重疊控件的大小時),都會調用這些方法,drawArgs方法參數包含繪制覆蓋圖所需的信息。本示例使用以下屬性:
下面的代碼段顯示了如何更新當前示例來在自定義位置顯示按鈕和標簽。
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技術交流群3:700924826 歡迎一起進群討論
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都網