数百个自定义用户控件创建数千个用户对象

发布于 2024-09-05 07:15:53 字数 849 浏览 2 评论 0原文

我正在创建一个仪表板应用程序,在 FlowLayoutPanel 上显示数百个“项目”。

每个“项目”都是一个由 12 个文本框或标签组成的 UserControl

我的应用查询数据库,然后为每条记录创建一个“item”实例,在将数据添加到 FlowLayoutPanel 之前用数据填充标签和文本框。

在向面板添加大约 560 个项目后,我注意到任务管理器中的USER Objects 计数已增加到大约 7300,这比我计算机上的任何其他应用程序都要大得多。

我计算出 560 * 13(12 个标签加上 UserControl 本身)是 7280。所以这突然泄露了所有对象的来源...

知道在 Windows 认输之前有 10,000 个 USER 对象限制,我'我试图找到将这些“项目”绘制到 FlowLayoutPanel 上的更好方法。

到目前为止,我的想法如下:

  1. 用户绘制“项目”,使用graphics.DrawTextDrawImage代替许多标签。我希望这意味着 1 个项目 = 1 个USER Object,而不是 13。

  2. 有 1 个“项目”实例,然后对于每条记录,填充该实例并使用 Control.DrawToBitmap() 方法来抓取图像,然后在 FlowLayoutPanel (或类似)中使用该图像

所以...有人还有其他建议吗???

PS 这是一个可缩放的界面,所以我已经排除了“分页”,因为需要一次查看所有项目

I'm creating a dashboard application that shows hundreds of "items" on a FlowLayoutPanel.

Each "item" is a UserControl that is made up of 12 textboxes or labels.

My app queries a database and then creates an "item" instance for each record, populating the labels and textboxes with data before adding it to the FlowLayoutPanel.

After adding about 560 items to the panel, I noticed that the USER Objects count in my Task Manager had gone up to about 7300, which was much much larger than any other app on my machine.

I figured that 560 * 13 (12 labels plus the UserControl itself) is 7280. So that suddenly gave away where all the objects were coming from...

Knowing that there is a 10,000 USER object limit before windows throws in the towel, I'm trying to figure better ways of drawing these "items" onto the FlowLayoutPanel.

My ideas so far are as follows:

  1. User-draw the "item", using graphics.DrawText and DrawImage in place of many of the labels. I'm hoping that this will mean 1 item = 1 USER Object, not 13.

  2. Have 1 instance of the "item", then for each record, populate the instance and use the Control.DrawToBitmap() method to grab an image and then use that in the FlowLayoutPanel (or similar)

So... Does anyone have any other suggestions ???

P.S. It's a zoomable interface, so I have already ruled out "paging" as there is a requirement to see all items at once

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

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

发布评论

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

评论(3

对你的占有欲 2024-09-12 07:15:53

至少,我会从你的想法#1 开始。这确实会减少应用程序占用的窗口数量 13 倍。

关于你的想法#2,如果你将位图放入 PictureBox(或其他)中,那么这对你根本没有帮助窗体上有大量 PictureBox 控件(这甚至可能更糟,因为位图有时由比一般 RAM 更有限的资源组成,这与消耗太多窗口是完全不同的问题)。只有当您获取生成的位图并将它们复制到单个较大的控件上(然后处理位图)时,这才是一个好主意。

如果您采用后一种方法,那么实际上不需要利用渲染到控件、获取控件的位图副本然后将该位图绘制到最终控件上的中间步骤。采用用于呈现控件的代码/逻辑,而不是直接呈现到最终(多元素)控件会更有意义。

At a minimum, I would start with your idea #1. This will indeed reduce the number of windows your application is gobbling up by a factor of 13.

Regarding your idea #2, that won't really help you at all if you then put the Bitmap into a PictureBox (or whatever) and thus have a large number of PictureBox controls on your form (this could even be worse, since Bitmaps sometimes are composed of a more limited resource than general RAM, which is an entirely different problem from consuming too many windows). This would only be a good idea if you were taking the resulting Bitmaps and copying them onto a single larger control (and then Disposing the Bitmaps).

If you take this latter approach, then there's really no need to utilize the intermediate step of rendering to a control, getting a Bitmap copy of the control and then drawing that Bitmap onto a final control. It would make more sense to take the code/logic that you use to render the control, and instead render directly to the final (multi-element) control.

镜花水月 2024-09-12 07:15:53

我会推荐你​​的想法#2。这正是用于显示数千条记录的列表和网格控件能够执行in-进行编辑。您从一个控件开始,然后将其移动到您需要的任何地方。

如果您需要同时显示多个实例,那么这就有点困难 - 正如您所提到的,您很可能必须使用 DrawToBitmap 并显示控件的“重影图像”。

或者,我假设这里正在进行一些滚动(实际上没有人可以同时查看 7280 个 UI 对象,对吧?),因此您可以做的另一件事是仅动态创建实际上将出现在屏幕上的实例同时。您必须计算可见区域并将其与要显示的控件列表进行比较,并且如果 UI 缩小太多而无法实际显示任何详细信息,则仅显示占位符。我想如果你这样做的话,滚动/缩放将成为一个相当 CPU 密集型的操作;最好根本不创建它们。

Your idea #2 is the one I would recommend. This is exactly how list and grid controls intended to display thousands of records are able to perform in-place editing. You start with just one control, and move it around to wherever you need it.

If you need to display several instances at the same time then it's a little bit harder - as you mention, you would most likely have to use DrawToBitmap and display the "ghost image" of the control.

Alternatively, I assume that there's some scrolling going on here (nobody can actually look at 7280 UI objects at once, right?), so the other thing you could do is dynamically create only the instances which are actually going to be on the screen at the same time. You'd have to calculate the visible area and compare that against the list of controls to be displayed, and just display placeholders if the UI is zoomed out too much to actually make out any details. I imagine that scrolling/zooming would become a pretty CPU-intensive operation if you did this, though; better to just not create them at all.

嘿嘿嘿 2024-09-12 07:15:53

我已经实施了#1,并取得了良好的效果。

用户对象减少了 13 倍,而且感觉更快、响应更灵敏。

感谢您的建议 - 我很惊讶这不是一个更常见的问题!

I've implemented #1 with good results.

13x less user objects, and it also feels faster and more responsive.

Thanks for the suggestions - I'm surprised that this isn't a more common problem !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文