Launch a Progress Dialog to display how long it is taking to complete some event.
[C#]
/// <summary> /// Launch a Progress Dialog to display how long it is taking to complete some event. /// </summary> /// <param name="application">An IApplication interface.</param> /// <param name="int32_Minimum">A System.Int32 that is the starting point for the progress display. Example: 0</param> /// <param name="int32_Maximum">A System.Int32 that is the ending point for a progress display. Example: 10000</param> /// <param name="string_Message">A System.String that is the message you want to user to see. Example: "Parsing Data, Please Wait.</param> /// <remarks> /// Calling this sub/method by itself is only half of the programming effort. Inside of the For loop you do something /// that requires time to progress. /// </remarks> public void ShowProgressDialog(ESRI.ArcGIS.Framework.IApplication application, System.Int32 int32_Minimum, System.Int32 int32_Maximum, System.String string_Message) { // Create a CancelTracker ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass(); // Set the properties of the Step Progressor System.Int32 int32_hWnd = application.hWnd; ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd); stepProgressor.MinRange = int32_Minimum; stepProgressor.MaxRange = int32_Maximum; stepProgressor.StepValue = 1; stepProgressor.Message = string_Message; // Create the ProgressDialog. This automatically displays the dialog ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog2 = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast // Set the properties of the ProgressDialog progressDialog2.CancelEnabled = true; progressDialog2.Description = "Counting to " + int32_Maximum.ToString() + "."; progressDialog2.Title = "Counting..."; progressDialog2.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriDownloadFile; // Step. Do your big process here. System.Boolean boolean_Continue = false; boolean_Continue = true; System.Int32 i = 0; for (i = int32_Minimum; i <= int32_Maximum; i++) { ESRI.ArcGIS.esriSystem.IStatusBar statusBar = application.StatusBar; statusBar.set_Message(0, i.ToString()); //TODO: //Ideally you would call another sub/function/method from here to do the //work. For example read all files of a specified types on disk, loop //through a recordset, etc. //... //Check if the cancel button was pressed. If so, stop process boolean_Continue = trackCancel.Continue(); if (!boolean_Continue) { break; } } // Done trackCancel = null; stepProgressor = null; progressDialog2.HideDialog(); progressDialog2 = null; }
[Visual Basic .NET]
''' <summary> ''' Launch a Progress Dialog to display how long it is taking to complete some event. ''' </summary> ''' <param name="application">An IApplication interface.</param> ''' <param name="int32_Minimum">A System.Int32 that is the starting point for the progress display. Example: 0</param> ''' <param name="int32_Maximum">A System.Int32 that is the ending point for a progress display. Example: 10000</param> ''' <param name="string_Message">A System.String that is the message you want to user to see. Example: "Parsing Data, Please Wait.</param> ''' <remarks> ''' Calling this sub/method by itself is only half of the programming effort. Inside of the For loop you do something ''' that requires time to progress. ''' </remarks> Public Sub ShowProgressDialog(ByVal application As ESRI.ArcGIS.Framework.IApplication, ByVal int32_Minimum As System.Int32, ByVal int32_Maximum As System.Int32, ByVal string_Message As System.String) ' Create a CancelTracker Dim trackCancel As ESRI.ArcGIS.esriSystem.ITrackCancel = New ESRI.ArcGIS.Display.CancelTrackerClass Dim progressDialogFactory As ESRI.ArcGIS.Framework.IProgressDialogFactory = New ESRI.ArcGIS.Framework.ProgressDialogFactoryClass ' Set the properties of the Step Progressor Dim int32_hWnd As System.Int32 = application.hWnd Dim stepProgressor As ESRI.ArcGIS.esriSystem.IStepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd) stepProgressor.MinRange = int32_Minimum stepProgressor.MaxRange = int32_Maximum stepProgressor.StepValue = 1 stepProgressor.Message = string_Message ' Create the ProgressDialog. This automatically displays the dialog Dim progressDialog2 As ESRI.ArcGIS.Framework.IProgressDialog2 = CType(stepProgressor, ESRI.ArcGIS.Framework.IProgressDialog2) ' Explict Cast ' Set the properties of the ProgressDialog progressDialog2.CancelEnabled = True progressDialog2.Description = "Counting to " + int32_Maximum.ToString + "." progressDialog2.Title = "Counting..." progressDialog2.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriDownloadFile ' Step. Do your big process here. Dim boolean_Continue As System.Boolean boolean_Continue = True Dim i As System.Int32 For i = int32_Minimum To int32_Maximum Dim statusBar As ESRI.ArcGIS.esriSystem.IStatusBar = application.StatusBar statusBar.Message(0) = i.ToString 'TODO: 'Ideally you would call another sub/function/method from here to do the 'work. For example read all files of a specified types on disk, loop 'through a recordset, etc. '... 'Check if the cancel button was pressed. If so, stop process boolean_Continue = trackCancel.Continue If Not boolean_Continue Then Exit For End If Next i ' Done trackCancel = Nothing stepProgressor = Nothing progressDialog2.HideDialog() progressDialog2 = Nothing End Sub