本篇文章為大家展示了如何使用DevExpress WinForms幫助文檔表單和用戶控件實(shí)現(xiàn)覆蓋表單,內(nèi)容簡明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),永仁企業(yè)網(wǎng)站建設(shè),永仁品牌網(wǎng)站建設(shè),網(wǎng)站定制,永仁網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,永仁網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
覆蓋表單是執(zhí)行以下操作的半透明啟動(dòng)屏幕:
覆蓋控件或表單
防止用戶與重疊控件進(jìn)行交互
覆蓋控件,即使它更改其大小或在屏幕上的位置
在單獨(dú)的線程中運(yùn)行,并且不阻塞主線程和操作線程
允許您在重疊控件上顯示自定義消息和按鈕
注意:運(yùn)行Overlay Form module in the XtraEditors MainDemo來查看正在使用的表單,單擊功能區(qū)中的Open Solution獲取源代碼。
顯示覆蓋表單
調(diào)用ShowOverlayForm(Control) 方法來在控件或表單上顯示覆蓋表單,該方法返回一個(gè)句柄,您可以將其傳遞給 CloseOverlayForm(IOverlaySplashScreenHandle)方法以關(guān)閉表單。
下面的代碼顯示在應(yīng)用程序執(zhí)行長時(shí)間運(yùn)行的操作時(shí)如何在當(dāng)前表單上顯示覆蓋表單。
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
警告:您只能在已初始化(創(chuàng)建其句柄)的控件/表單上顯示覆蓋表單;否則將拋出InvalidOperationException,請(qǐng)參見 IsHandleCreated 。
自定義覆蓋表單
ShowOverlayForm(Control, OverlayWindowOptions) 方法允許您顯示具有以下參數(shù)的覆蓋表單:
StartupDelay — 顯示表單之前的延遲。
BackColor — 背景顏色。
Opacity — 不透明表單。
FadeIn, FadeOut — 用于顯示和隱藏表單的淡入淡出效果。
AnimationType — 動(dòng)畫的類型(等待指示符):
Image — 旋轉(zhuǎn)的圖像,默認(rèn)圖像取決于皮膚。 使用ImageSize屬性指定默認(rèn)圖像的大小,默認(rèn)圖像大小取決于重疊控件的大小,Image屬性指定一個(gè)自定義圖像。
RotationParameters屬性指定旋轉(zhuǎn)周期和單旋轉(zhuǎn)幀數(shù)。
Line — 使用LineAnimationParameters屬性指定點(diǎn)數(shù),點(diǎn)的大小以及點(diǎn)之間的距離。
CustomPainter — 一個(gè)用于繪制表單的OverlayWindowPainterBase后代,請(qǐng)參閱Custom Painter部分中的示例。
SkinName — 應(yīng)用于表單的skin名稱,默認(rèn)的等待指示器,淡入淡出效果和顏色取決于皮膚,默認(rèn)外觀對(duì)應(yīng)于重疊控件的外觀
UseDirectX — 指定是否使用DirectX渲染覆蓋表單,要將DirectX用于所有兼容的DevExpress控件,請(qǐng)?jiān)赑roject Settings中啟用Use DirectX選項(xiàng),有關(guān)更多信息,請(qǐng)參閱以下主題: DirectX Hardware Acceleration。
所有這些參數(shù)都是可選的。 如果省略參數(shù),則使用默認(rèn)值。 不帶選項(xiàng)的ShowOverlayForm(Control)方法使用靜態(tài)(在VB中共享)默認(rèn)選項(xiàng)。
下面的代碼顯示了如何顯示帶有自定義參數(shù)的覆蓋表單。
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) )
自定義Painter
您可以按以下方式呈現(xiàn)重疊表單:
繼承自O(shè)verlayWindowPainterBase類
重寫Draw方法
將創(chuàng)建的對(duì)象作為參數(shù)傳遞給ShowOverlayForm方法
下面的代碼段顯示了如何顯示自定義消息,如下圖所示:
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())
上述內(nèi)容就是如何使用DevExpress WinForms幫助文檔表單和用戶控件實(shí)現(xiàn)覆蓋表單,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
網(wǎng)頁題目:如何使用DevExpressWinForms幫助文檔表單和用戶控件實(shí)現(xiàn)覆蓋表單
鏈接地址:http://chinadenli.net/article46/gpdihg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化、軟件開發(fā)、外貿(mào)建站、網(wǎng)站營銷、響應(yīng)式網(wǎng)站、微信公眾號(hào)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)