With .NET it is easy. One way is to use Inherit Control project or simply create a dll with the following code.
So, you need a progress bar in a StatusBar then inherit from StstusBar and add there the controls you want such ProgressBar, ComboBox, TreeView etc.
Code:
using System;
using System.Windows.Forms;
namespace MySB
{
/// <summary>
/// Summary description for MyStatusBar.
/// </summary>
public class MyStatusBar: System.Windows.Forms.StatusBar
{
public System.Windows.Forms.ProgressBar progress = new System.Windows.Forms.ProgressBar();
public MyStatusBar()
{
this.Controls.Add(progress);
this.Panels.Add("progress");
this.Panels[0].AutoSize=StatusBarPanelAutoSize.Spring;
this.ShowPanels=true;//false
}
private void MyStatusBar_Resize(object sender, System.EventArgs e)
{
progress.Left=0;
progress.Width=this.Panels[0].Width;
progress.Height=this.Height -2;
progress.Top= 2;
Invalidate();
}
public int Value
{
get {return progress.Value;}
set {progress.Value= value;}
}
}
}
The above code will produce the MySB.dll.
Next, add this control (MySB.dll) in the ToolBox by creating it in My User Control tab.
If you have not yet this one, add new tab using ToolBox->Add Tab. Next select My User Control tab and use Add/Remove to add the above control myStatusBar.
Browse to locate the MySB.dll. You should see now in ToolBox on your VS.NET the MyStatusBar contril.
Next, add this control in your form as a regular StatusBar.
Build and run. You should see the status bar there.
Now, to see the progress bar working in the status bar just run this code:
Code:
private void button1_Click(object sender, System.EventArgs e)
{
TestProgressBar(10);
}
private void TestProgressBar(int num)
{
this.myStatusBar1.Visible = true;
myStatusBar1.progress.Minimum = 1;
myStatusBar1.progress.Maximum = num;
myStatusBar1.progress.Value = 1;
myStatusBar1.progress.Step = 1;
// Loop through .
for (int x = 1; x <= num; x++)
{
myStatusBar1.progress.PerformStep();
System.Threading.Thread.Sleep(1000);
}
}
-obislavu-