點擊獲取工具>>git
注意:GitHub上提供了完整的示例項目,網址爲:https://github.com/DevExpress-Examples/how-to-display-a-custom-button-on-an-overlay-formgithub
Overlay Form是一個半透明的啓動屏幕,他在後臺線程中運行並覆蓋控件或表單來防止對其進行訪問,Overlay Form僅包含一個等待指示器。express
本示例演示如何顯示:async
本示例使您能夠更改標籤文本、按鈕字形以及單擊按鈕時執行的操做。ide
您能夠按如下方式自定義Overlay Form圖形:工具
本示例使用OverlayImagePainter和OverlayTextPainter對象(OverlayWindowPainterBase後代),它們實現了圖像和文本的繪製邏輯,而且您能夠使用它們的屬性來自定義圖像和文本。佈局
OverlayImagePainter對象在Overlay Form的頂部中心繪製一個自定義圖像,並處理該圖像上的單擊。 您能夠指定如下屬性:字體
OverlayTextPainter對象在等待指示器下方繪製一個自定義標籤,您能夠指定如下屬性:this
OverlayWindowCompositePainter對象在OverlayImagePainter和OverlayTextPainter對象中組成繪圖邏輯,該複合繪製器做爲參數傳遞給SplashScreenManager.ShowOverlayForm方法。spa
顯示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
`
下圖說明了生成的佈局。