Updating a Gauge and Detecting a User Interrupt (Visual Basic)
Take the following steps to update a gauge during processing and detect a user interrupt:
1. |
Start with the project that you created in Loading and Displaying an Image. |
2. |
Add the LEAD RasterProcess Object Library to your project. |
|
On the Project pull-down menu, use the References option, and select the LEAD RasterProcess Object Library (14.5). |
3. |
Select the CommandButton control; then add the control to your main form. Put the control at the top of the form to keep it away from the image. |
4. |
In the Properties box, change the CommandButton control's Caption property to Do Median. |
5. |
Select the CommandButton control; then add another control to your main form. Put the control at the top of the form to keep it away from the image. |
6. |
In the Properties box, change the CommandButton control's Caption property to Quit. |
7. |
Build a gauge consisting of a horizontal line (Line1) inside a rectangle (Shape1). Put the gauge at the top of the form next to the Quit button. |
8. |
Add the following code to the general declarations: |
Dim fEscape As Integer 'Use to indicate the user interrupt
Dim fInProc As Integer 'Use to avoid closing the form during processing
Public WithEvents RasterProc As LEADRasterProcess
9. |
Now, add the following to the Form's Load event to create the ILEADRasterProcess object |
'Create the RasterProcess Object
Set RasterProc = CreateObject("LEADRasterProcess.LEADRasterProcess. ")
10. |
Add the following code to the first CommandButton control's Click procedure: |
Private Sub Command1_Click ()
'Enable the ProgressStatus event
RasterProc.EnableProgressEvent = True
'Initialize the indicators
fEscape = False 'The user does not want to quit
fInProc = True 'Processing is taking place
'Perform a relatively slow median filter
RasterProc.Median LEADRasterView1.Raster, 4
'Clean up
fInProc = False 'Processing is no longer taking place
LEADRasterView1.ForceRepaint
End Sub
11. |
Add the following code to handle the RasterProc object's ProgressStatus procedure: |
RasterProc_ProgressStatus(ByVal iPercent As Integer)
Dim LineLength
DoEvents 'Detect Windows events
If Not fEscape Then ' Look for the Click on the Quit button
LineLength = Form1.Shape1.Width * iPercent / 100 'Udpate the gauge
Me.Line1.X1 = Me.Shape1.Left
Me.Line1.X2 = Me.Line1.X1 + LineLength
Else
RasterProc.EnableProgressEvent = False 'Cancel the task
End If
End Sub
12. |
Add the following code to the second CommandButton control's Click procedure: |
Private Sub Command2_Click ()
fEscape = True 'The user wants to quit
Me.Line1.X2 = Me.Line1.X1 'Set the gauge back to the beginning
End Sub
13. |
Add the following code to the main form's QueryUnload procedure: |
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If fInProc Then 'If processing is taking place
Cancel = 1 'Do not let the user close the form
End If
End Sub
14. |
Run your program to test it. |