带图标的 GDI 句柄。 我
我有一个winforms应用程序。 我有一个带有很多图标的用户控件。 用户可以在表单上多次加载此控件(在选项卡式布局中)。 现在,每次创建控件时我都会加载图标(在应用程序中最多可能加载 50 次)。 有什么方法可以在应用程序中缓存这些图标。 如果我这样做,是否会减少我正在使用的 GDI 句柄的数量,因为这正在成为一个问题。
i have a winforms application. i have a user control with a lot of icons. the user can load this control on a form many times (in a tabbed layout). right now i am loading the icons each time the control is created (could be up to 50 times in teh app). is there any way to cache these icons in the application. if i did this, would that decrease the number of gdi handles that i am using as this is becoming an issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以为每个图标创建一个单例类。 它创建句柄的第一个引用。 后续调用将使用现有句柄。
如果不了解有关用户控制的更多信息,我的下一个建议只能是非常笼统的。 但是您可以使用一个位图图层来在其上绘制所有图标。 用户控件的其余元素将存在于该位图的上方和周围。
不幸的是,这个想法可能会带来性能问题。 要求您重构所有准备用于排列图标的代码。 最后,从具有控制形式结构的框架如何理想地工作来看,它是非制度性的。
我们在 CAM 软件附带的参数形状输入表单方面遇到了资源问题。 太多的文本条目导致了各种形式的奇怪和泄漏。 因此,我们创建了带有边框的标签,这些标签看起来像文本条目,并且有一个文本条目(还有一个组合框条目)。 当用户选项卡、输入或单击时,单个文本条目会移动到新条目,并且标签会为前一个条目设置。
与通常的编码方式相比,这完全是一种不直观的设置,但这是处理我们的资源问题的唯一方法。
根据我的经验,当您必须处理数十或数百个条目并且必须使用不同的设计来解决问题时,GUI 框架似乎会出现问题。
You can make a singleton class for each icon. The first reference it creates the handle. Subsequent calls uses the existing handle.
Without knowing more about your user control my next suggestion can be only be very general. But you could have a single bitmap layer on which you draw all your icons. The remaining elements of your user control would exists above and around this bitmap.
Unfortunately this idea may be problematic performance wise. Require you to refactor the code you all ready use for arranging icons. Finally it is non-institutive from how frameworks with a control-form structure ideally works.
We ran into a resource problem with entry forms for the parameteric shape we ship with our CAM software. Too many text entries caused various forms of strangeness and leaks. So we instead created labels with borders that looked like text entries and had ONE text entry (and a combo box entry too). When the user tabs, enters, or clicked the single text entry moved to the new entry and the label was setup for the previous entry.
This is totally a non-intuitive setup than how you would normally code this but it was the only way to deal with our resource problem.
In my experience it seems that GUI Frameworks have issues when you have to deal with dozens or hundreds of entries and that you have to approach the problem using a different design.
如果问题是“图标”的数量(不确定您在这里的意思),您可以使用图像列表。 例如,列表视图控件可以引用图像列表中的图标,而不是为每个项目保留完整副本(但不确定这是否适用于您的情况)。
If the issue is the number of "icons" (not sure what you mean here) you can use Image-Lists. For example, a Listview control can reference icons in an image-list, instead of keeping a full copy for each item (not sure if this applies to your case though).