I have an application where there can be several lengthy (minutes) tasks happening simultaneously in the background (i.e. the same task for different accounts, some accounts taking longer than others). I would like to show a progress bar and status text for each task in parallel. I supposed I could show that in a different window if there were many such accounts, but for now the scenario is just to have 2-4 accounts, therefore I'd like to show the progress bars in a StatusStrip at the bottom of the main form. I am thinking the StatusStrip should grow up and I would add ToolStripProgressBar's and ToolStripStatusLabel's one above the other dynamically, based on the number of accounts being processed at any given time. Is this possible? I was thinking of using a TableLayoutPanel inside the StatusStrip, but Visual Studio designer only allows very few components to be added to a StatusStrip. Is there any issue with me adding this programtically?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Probably it's not an intelligent UI design, but just for your information, you can add any control using ToolStripControlHost
. Here is a simple example which lets you add multiple StatusBar
controls in a single item of StatusStrip
using code:
ToolStripControlHost host;
FlowLayoutPanel panel;
private void button1_Click(object sender, EventArgs e)
{
if (panel == null)
{
panel = new FlowLayoutPanel();
panel.FlowDirection = FlowDirection.TopDown;
panel.WrapContents = false;
panel.AutoSize = true;
panel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
}
if (host == null)
{
host = new ToolStripControlHost(panel);
this.statusStrip1.Items.Add(host);
}
panel.Controls.Add(new ProgressBar() { /* Value = new Random().Next(0, 100) */ });
}
Note: You also can extend ToolStripControlHost
to provide design-time support, to do so take a look at How to: Wrap a Windows Forms Control with ToolStripControlHost.