C# - 多个进度条列表。使用什么组件?

发布于 2024-09-27 18:29:22 字数 174 浏览 2 评论 0原文

我有一个应用程序,需要将多个进度条动态添加到表单中(每当添加并开始新的上传时)。

我一直在谷歌搜索,结果建议在 ListView 或 DataGridView 中嵌入进度条。

任何人都可以建议任何其他技术,因为到目前为止我所看到的 ListView 或 DataGridView 黑客似乎都没有吸引力?

I have an app that requires multiple progress bars to be added dynamically to a form (whenever a new upload is added and started).

I've been Googling and the results suggested embedding progress bars in a ListView or a DataGridView.

Can anyone suggest any other techniques, as neither ListView or DataGridView hacks I've seen so far seem appealing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

赏烟花じ飞满天 2024-10-04 18:29:22

我建议创建一个自定义控件,也许使用面板作为基本控件。添加进度条、文件名、其他文件信息等控件,并将所有内容公开为属性。编写函数,以便它们自动处理自己的进度。

通过这种方式,您可以像其他任何东西一样实例化它们,并将它们添加到滚动区域,而不必过多担心每个属性。这只是帮助您入门的基本想法。如果这还不够清楚,请告诉我。

以下是创建自定义控件的一个相对完整的示例: http://www.akadia.com/services/ dotnet_user_controls.html

I would recommend creating a custom control, perhaps using a Panel as a base control. Add the controls for the progress bar, file name, other file information, etc.. and expose everything as properties. Write the functions so that they automatically handle their own progress.

This way you can instantiate them like anything else, and add them to a scrolling area, without having to worry too much about the properties of each. This is just a base idea to get you started. Let me know if this isn't clear enough.

Here's one relatively thorough example of creating a custom control: http://www.akadia.com/services/dotnet_user_controls.html

怎樣才叫好 2024-10-04 18:29:22

我猜是 TableLayoutPanel 会更容易。

为每个 ProgressBar 添加一列并添加一行。
或者两列,一列带有 Label,一列带有 ProgressBar

I guess a TableLayoutPanel would be easier.

One column and add a row for each ProgressBar.
Or two columns, one with a Label and one with the ProgressBar.

飞烟轻若梦 2024-10-04 18:29:22

我个人对它们了解不多,但我认为如果您使用后台工作人员,他们可能会提供帮助,因为您可以调用一个方法来通知程序已取得进展,并且您可以更新进度栏。< a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx" rel="nofollow" title="后台工作人员">后台工作人员

I personally don't know much about them myself but I think if you used Background workers they mgiht be able to help as you can call a method that notifies the program that progress has been made and with that you can update the progress bar.Background worker

荒芜了季节 2024-10-04 18:29:22

如果允许使用第三方控件,我建议使用类似 XtraGrid< /a> 来自 DevEx。这很容易实现,你会觉得自己在作弊。

If using third party controls is allowed, I would suggest something like XtraGrid from DevEx. It will be so easy to pull off you'll feel you are cheating.

り繁华旳梦境 2024-10-04 18:29:22

另一种方法是使用 OwnerDraw 属性为 true 的 ListView 并响应 DrawSubItem() 事件。使用已提供的 e.Graphics 对象在事件参数中给出的给定矩形 e.Bounds 内绘制进度条非常简单。

这是一个例子

private void lvUsers_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
    if (e.ColumnIndex == 5)
    {
        e.DrawDefault = false;
        Rectangle bounds = e.Bounds;
        double pct = ...;
        Rectangle fill = new Rectangle(
            bounds.Left, bounds.Top,
            (int)(pct * bounds.Width), bounds.Height);
        using (LinearGradientBrush lg = ...)
        {
            e.Graphics.FillRectangle(lg, fill);
        }
        e.Graphics.DrawRectangle(Pens.Black, bounds);
       ...
    }
    else
    {
        e.DrawDefault = true;
    }
}

An alternative is to use a ListView with OwnerDraw property true and respond to the DrawSubItem() event. Drawing a progress bar is supereasy within the given rectangle e.Bounds that is given in the event arguments using the already supplied e.Graphics object.

Here is an example

private void lvUsers_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
    if (e.ColumnIndex == 5)
    {
        e.DrawDefault = false;
        Rectangle bounds = e.Bounds;
        double pct = ...;
        Rectangle fill = new Rectangle(
            bounds.Left, bounds.Top,
            (int)(pct * bounds.Width), bounds.Height);
        using (LinearGradientBrush lg = ...)
        {
            e.Graphics.FillRectangle(lg, fill);
        }
        e.Graphics.DrawRectangle(Pens.Black, bounds);
       ...
    }
    else
    {
        e.DrawDefault = true;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文