-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.vb
More file actions
66 lines (59 loc) · 3.01 KB
/
Form1.vb
File metadata and controls
66 lines (59 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Imports System
Imports System.Windows.Forms
Imports System.Threading
Imports DevExpress.Office.Services
Imports DevExpress.Office.Services.Implementation
Imports DevExpress.Services
Namespace SpreadsheetProgressSample
Partial Public Class Form1
Inherits DevExpress.XtraBars.Ribbon.RibbonForm
Implements IProgressIndicationService
Private cancellationTokenSource As CancellationTokenSource
Private savedCancellationTokenProvider As ICancellationTokenProvider
Public Sub New()
InitializeComponent()
' Replace the default progress indication service
' with a custom service.
spreadsheetControl1.ReplaceService(Of IProgressIndicationService)(Me)
End Sub
Private Sub IProgressIndicationService_Begin(ByVal displayName As String, ByVal minProgress As Integer, ByVal maxProgress As Integer, ByVal currentProgress As Integer) Implements IProgressIndicationService.Begin
cancellationTokenSource = New CancellationTokenSource()
' Register a new CancellationTokenProvider instance
' to process cancellation requests. Save the reference
' to the previously registered service.
savedCancellationTokenProvider = spreadsheetControl1.ReplaceService(Of ICancellationTokenProvider)(New CancellationTokenProvider(cancellationTokenSource.Token))
splashScreenManager1.ShowWaitForm()
' Display the name of the running operation in the Wait Form.
splashScreenManager1.SetWaitFormCaption(displayName)
' Display the progress of the running operation in the Wait Form.
splashScreenManager1.SetWaitFormDescription($"{currentProgress}%")
' Send a command to the Wait Form
' to specify the CancellationTokenSource object
' used to generate cancellation tokens for the task cancellation.
splashScreenManager1.SendCommand(WaitForm1.WaitFormCommand.SetCancellationTokenSource, cancellationTokenSource)
End Sub
Private Sub IProgressIndicationService_End() Implements IProgressIndicationService.End
' Close the Wait Form.
If splashScreenManager1.IsSplashFormVisible Then
splashScreenManager1.CloseWaitForm()
End If
' Restore previous CancellationTokenProvider.
spreadsheetControl1.ReplaceService(savedCancellationTokenProvider)
spreadsheetControl1.UpdateCommandUI()
' Dispose the CancellationTokenSource object.
cancellationTokenSource?.Dispose()
cancellationTokenSource = Nothing
End Sub
Private Sub IProgressIndicationService_SetProgress(ByVal currentProgress As Integer) Implements IProgressIndicationService.SetProgress
' Display the progress of the running operation in the Wait Form.
splashScreenManager1.SetWaitFormDescription($"{currentProgress}%")
End Sub
Private Sub spreadsheetControl1_UnhandledException(ByVal sender As Object, ByVal e As DevExpress.XtraSpreadsheet.SpreadsheetUnhandledExceptionEventArgs) Handles spreadsheetControl1.UnhandledException
' Handle OperationCanceledException
' that is thrown when a user cancels the operation.
If TypeOf e.Exception Is OperationCanceledException Then
e.Handled = True
End If
End Sub
End Class
End Namespace