//呼び出し main m = new main(); m.ShowProgressDialog(ArcMap.Application, 0, 100, "テスト"); //定義 class main { public void ShowProgressDialog(ESRI.ArcGIS.Framework.IApplication application, System.Int32 int32_Minimum, System.Int32 int32_Maximum, System.String string_Message) { 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(null, int32_hWnd); stepProgressor.MinRange = int32_Minimum; stepProgressor.MaxRange = int32_Maximum; stepProgressor.StepValue = 2; // 2にすると上手くいっているように見える。(竹中) stepProgressor.Message = string_Message; // Create the ProgressDialog. This automatically displays the dialog ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog2 = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast try { // 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; int count = int32_Maximum - int32_Minimum; // Step. Do your big process here. for (System.Int32 i = 0; i < count; i++) { //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. //... stepProgressor.Message = string.Format("{0}件目を処理中です。", (i + 1).ToString()); if (stepProgressor.Position == stepProgressor.MaxRange) { stepProgressor.Position = stepProgressor.MaxRange; } else { stepProgressor.Step(); } // ★Step処理の後に一定時間Sleepを行う // 一定以上のSleep(500ms)を指定するとプログレスバーが概ね意図した通りに更新される // 一定時間より短く短くSleepを指定する(またはSleepを指定しない)場合、 // メッセージ内容(「xxx件目を処理中です。」)とプログレスバーの位置が同期しない Thread.Sleep(10); } // Done stepProgressor = null; progressDialog2.HideDialog(); progressDialog2 = null; } catch(Exception ex) { System.Diagnostics.Debug.Print(ex.Message); stepProgressor = null; progressDialog2.HideDialog(); progressDialog2 = null; } } }
プログレス ダイアログ(ProgressDialog)の作成
2016/9/1 (木)