YouTube | Facebook | X(Twitter) | RSS

プログレス ダイアログ(ProgressDialog)の作成

2016/9/1 (木)

//呼び出し
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;
        }
    }
}

関連記事

  • この記事を書いた人

羽田 康祐

伊達と酔狂のGISエンジニア。GIS上級技術者、Esri認定インストラクター、CompTIA CTT+ Classroom Trainer、潜水士、PADIダイブマスター、四アマ。WordPress は 2.1 からのユーザーで歴だけは長い。 代表著書『地図リテラシー入門―地図の正しい読み方・描き方がわかる』 GIS を使った自己紹介はこちら。ESRIジャパン(株)所属、元青山学院大学非常勤講師を兼務。日本地図学会第31期常任委員。発言は個人の見解です。

-プログラミング, ArcGIS
-,

WINGFIELD since1981をもっと見る

今すぐ購読し、続きを読んで、すべてのアーカイブにアクセスしましょう。

続きを読む