点击获取工具>>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
`
下图说明了生成的布局。