How to: 設計程式的狀態列上的進度列區域
進度列區域的Visual Studio ,狀態列會顯示快速作業,例如,將檔案儲存至磁碟的增加進度。
若要使用 Visual Studio 的狀態列上的進度列區域
取得執行個體的IVsStatusbar介面,可透過SVsStatusbar服務。
初始化進度列,開始值,藉由呼叫Progress方法。
更新進度列,您的作業進行時使用Progress方法,以設定新的值。
範例
本範例將示範如何初始化,並更新進度列。
Private Sub ProgressBarExample()
Dim statusBar As IVsStatusbar = DirectCast(GetService(GetType(SVsStatusbar)), IVsStatusbar)
Dim cookie As UInteger = 0
Dim label As String = "Progress bar label..."
' Initialize the progress bar.
statusBar.Progress(cookie, 1, "", 0, 0)
Dim i As UInteger = 0, total As UInteger = 100
While i <= total
' Display incremental progress.
statusBar.Progress(cookie, 1, label, i, total)
System.Threading.Thread.Sleep(1)
i += 1
End While
' Clear the progress bar.
statusBar.Progress(cookie, 0, "", 0, 0)
End Sub
void ProgressBarExample()
{
IVsStatusbar statusBar =
(IVsStatusbar)GetService(typeof(SVsStatusbar));
uint cookie = 0;
string label = "Progress bar label...";
// Initialize the progress bar.
statusBar.Progress(ref cookie, 1, "", 0, 0);
for (uint i = 0, total = 100; i <= total; i++)
{
// Display incremental progress.
statusBar.Progress(ref cookie, 1, label, i, total);
System.Threading.Thread.Sleep(1);
}
// Clear the progress bar.
statusBar.Progress(ref cookie, 0, "", 0, 0);
}
在範例中,程式碼:
取得執行個體的IVsStatusbar介面從SVsStatusbar服務。
初始化進度列,以指定起始值,藉由呼叫Progress方法。
逐一查看,以模擬作業for迴圈,並更新進度列的值,藉由使用Progress方法。
藉由清除進度列Clear方法。