Multiple Progress Bars in StatusStrip

守給你的承諾、 提交于 2019-12-02 13:14:51

问题


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.



来源:https://stackoverflow.com/questions/42027926/multiple-progress-bars-in-statusstrip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!