原創|使用教程|編輯:龔雪|2021-04-06 10:22:50.957|閱讀 302 次
概述:本文主要介紹DevExpress表單控件的覆蓋表單,覆蓋表單執行半透明啟動屏幕。歡迎下載最新版DevExpress體驗!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
覆蓋表單是執行以下操作的半透明啟動屏幕:
 
 
注意:運行Overlay Form module in the XtraEditors MainDemo來查看正在使用的表單,單擊功能區中的Open Solution獲取源代碼。
調用 方法來在控件或表單上顯示覆蓋表單,該方法返回一個句柄,您可以將其傳遞給 方法以關閉表單。
下面的代碼顯示在應用程序執行長時間運行的操作時如何在當前表單上顯示覆蓋表單。
C#
using DevExpress.XtraSplashScreen;
//...
IOverlaySplashScreenHandle ShowProgressPanel() {
return SplashScreenManager.ShowOverlayForm(this);
}
void CloseProgressPanel(IOverlaySplashScreenHandle handle) {
if(handle != null)
SplashScreenManager.CloseOverlayForm(handle);
}
//...
IOverlaySplashScreenHandle handle = null;
try {
handle = ShowProgressPanel();
// Launch a long-running operation while
// the Overlay Form overlaps the current form.
}
finally {
CloseProgressPanel(handle);
}
VB.NET
Imports DevExpress.XtraSplashScreen '... Private Function ShowProgressPanel() As IOverlaySplashScreenHandle Dim handle As IOverlaySplashScreenHandle = SplashScreenManager.ShowOverlayForm(Me) Return handle End Function Private Sub CloseProgressPanel(ByVal handle As IOverlaySplashScreenHandle) If handle IsNot Nothing Then SplashScreenManager.CloseOverlayForm(handle) End Sub '... Dim Handle As IOverlaySplashScreenHandle = Nothing Try Handle = ShowProgressPanel() 'Launch a long-running operation while 'the Overlay Form overlaps the main form. Finally CloseProgressPanel(Handle) End Try
警告:您只能在已初始化(創建其句柄)的控件/表單上顯示覆蓋表單;否則將拋出,請參見 。
方法允許您顯示具有以下參數的覆蓋表單:
所有這些參數都是可選的。 如果省略參數,則使用默認值。 不帶選項的方法使用靜態(在VB中共享)默認選項。
下面的代碼顯示了如何顯示帶有自定義參數的覆蓋表單。
C#
using DevExpress.XtraSplashScreen; OverlayWindowOptions options = new OverlayWindowOptions( startupDelay: 1000, backColor: Color.Red, opacity: 0.5, fadeIn: false, fadeOut: false, imageSize: new Size(64, 64) ); IOverlaySplashScreenHandle handle1 = SplashScreenManager.ShowOverlayForm(gridControl1, options); IOverlaySplashScreenHandle handle2 = SplashScreenManager.ShowOverlayForm( owner: gridControl1, startupDelay: 1000, backColor: Color.Red, opacity: 127, fadeIn: false, fadeOut: false, imageSize: new Size(64, 64) );
VB.NET
Imports DevExpress.XtraSplashScreen Dim options As New OverlayWindowOptions( startupDelay:=1000, backColor:=Color.Red, opacity:=0.5, fadeIn:=False, fadeOut:=False, imageSize:=New Size(64, 64) ) Dim formHandle1 As IOverlaySplashScreenHandle = SplashScreenManager.ShowOverlayForm(gridControl1, options) Dim formHandle2 As IOverlaySplashScreenHandle = SplashScreenManager.ShowOverlayForm( owner:=gridControl1, startupDelay:=1000, backColor:=Color.Red, opacity:=127, fadeIn:=False, fadeOut:=False, imageSize:=New Size(64, 64) )
您可以按以下方式呈現重疊表單:
下面的代碼段顯示了如何顯示自定義消息,如下圖所示:
 
 
C#
using DevExpress.XtraSplashScreen;
using DevExpress.Utils.Drawing;
using System.Drawing;
//...
class CustomOverlayPainter : OverlayWindowPainterBase
{
// Defines the string’s font.
static readonly Font drawFont;
static CustomOverlayPainter() {
drawFont = new Font("Tahoma", 18);
}
protected override void Draw(OverlayWindowCustomDrawContext context)
{
//The Handled event parameter should be set to true. 
//to disable the default drawing algorithm. 
context.Handled = true;
//Provides access to the drawing surface. 
GraphicsCache cache = context.DrawArgs.Cache;
//Adjust the TextRenderingHint option
//to improve the image quality.
cache.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
//Overlapped control bounds. 
Rectangle bounds = context.DrawArgs.Bounds;
//Draws the default background. 
context.DrawBackground();
//Specify the string that will be drawn on the Overlay Form instead of the wait indicator.
String drawString = "Please wait...";
//Get the system's black brush.
Brush drawBrush = Brushes.Black;
//Calculate the size of the message string.
SizeF textSize = cache.CalcTextSize(drawString, drawFont);
//A point that specifies the upper-left corner of the rectangle where the string will be drawn.
PointF drawPoint = new PointF(
bounds.Left + bounds.Width / 2 - textSize.Width / 2,
bounds.Top + bounds.Height / 2 - textSize.Height / 2
);
//Draw the string on the screen.
cache.DrawString(drawString, drawFont, drawBrush, drawPoint);
}
}
//...
IOverlaySplashScreenHandle handle = SplashScreenManager.ShowOverlayForm(this, customPainter: new CustomOverlayPainter());
VB.NET
Imports DevExpress.Utils.Drawing
Imports DevExpress.XtraSplashScreen
Imports System.Drawing
'...
Class CustomOverlayPainter
Inherits OverlayWindowPainterBase
'Defines the string’s font.
Shared ReadOnly drawFont As Font
Shared Sub New()
drawFont = New Font("Tahoma", 18)
End Sub
Protected Overrides Sub Draw(context As OverlayWindowCustomDrawContext)
'The Handled event parameter should be set to true 
'to disable the default drawing algorithm.
context.Handled = True
'Provides access to the drawing surface. 
Dim cache As GraphicsCache = context.DrawArgs.Cache
'Adjust the TextRenderingHint option 
’to improve the image quality. 
cache.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias
'Overlapped control bounds.
Dim bounds As Rectangle = context.DrawArgs.Bounds
'Draws the default background. 
context.DrawBackground()
'Create the string to draw. 
Dim drawString As String = "Please wait..."
'Get the system black brush. 
Dim drawBrush As Brush = Brushes.Black
'Calculate the size of the message string. 
Dim textSize As SizeF = cache.CalcTextSize(drawString, drawFont)
'A point that specifies the upper-left corner of the rectangle where the string should be drawn.
Dim drawPoint As PointF = New PointF(bounds.Left + bounds.Width / 2 - textSize.Width / 2, bounds.Top + bounds.Height / 2 - textSize.Height / 2)
'Draw the string on the screen.
cache.DrawString(drawString, drawFont, drawBrush, drawPoint)
End Sub
End Class
'...
Dim handle As IOverlaySplashScreenHandle = SplashScreenManager.ShowOverlayForm(Me, customPainter:=New CustomOverlayPainter())
DevExpress技術交流群3:700924826 歡迎一起進群討論
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn
文章轉載自:慧都網