StatusStrip中的多个进度条 [英] Multiple Progress Bars in StatusStrip

查看:207
本文介绍了StatusStrip中的多个进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,在后台可以同时执行多个冗长(分钟)的任务(即,对于不同的帐户而言,这是同一任务,某些帐户所花的时间比其他帐户要长).我想并行显示每个任务的进度条和状态文本.我以为如果有很多这样的帐户,我可以在另一个窗口中显示出来,但目前情况是只有2-4个帐户,因此我想在主窗口底部的StatusStrip中显示进度条形式.我认为StatusStrip应该长大,并且我会根据在任何给定时间处理的帐户数,动态地将ToolStripProgressBar和ToolStripStatusLabel彼此相加.这可能吗?我当时在考虑在StatusStrip中使用TableLayoutPanel,但是Visual Studio设计器仅允许将很少的组件添加到StatusStrip中.我以编程方式添加此内容有什么问题吗?

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?

推荐答案

可能不是智能UI设计,但是仅出于您的信息,您可以使用

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) */ });
}

注意:您还可以扩展ToolStripControlHost以提供设计时支持,为此,请查看

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.

这篇关于StatusStrip中的多个进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆