如何确定 PropertyGrid 控件何时要修改对象的属性
我有一个扩展 PropertyGrid 的控件,它允许用户设置我的一些程序对象的属性。这些对象有一个事件,当它们的属性之一更改时会引发该事件,并且 PropertyGrid 订阅该事件,以便在属性更改时刷新自身。当选择大量对象并且用户一次在所有对象上设置属性时,就会出现我的问题。该控件被 Refresh() 请求淹没,这需要很长时间(例如,在打开自动刷新功能的情况下,为大约 300 个对象设置属性大约需要 20 秒,而在打开自动刷新功能时只需要几分之一秒离开)。
我想在属性网格设置属性的过程中阻止事件处理程序刷新网格,但不幸的是我无法找到任何方法来确定网格何时“开始”和“停止”设置该财产。我希望有一些方法或我可以覆盖的东西,例如......
override void OnSetPropertyStart()
{
suppressRefresh = true;
}
override void OnSetPropertyEnd()
{
suppressRefresh = false;
}
不幸的是,情况似乎并非如此。是否有其他方法可以确定属性网格何时设置属性,或者以其他方式实现相同的效果?
I have a control extending PropertyGrid which allows users to set the properties of some of my program objects. These objects have an event which is raised when one of their properties changes, and the PropertyGrid subscribes to this event so that it refreshes itself when a property is changed. My problem occurs when large numbers of objects are selected, and the user sets a property on all of the objects at once. The control gets swamped with Refresh() requests, which take a long time (for example, setting a property on ~300 objects takes about 20 seconds with the auto-refresh feature turned on, and just a fraction of a second when it is turned off).
I would like to prevent the event handler from refreshing the grid while the property grid is in the process of setting a property, but unfortunately I haven't been able to find any way to determine when the grid "starts" and "stops" setting the property. I was hoping there would be methods or something I could override, such as...
override void OnSetPropertyStart()
{
suppressRefresh = true;
}
override void OnSetPropertyEnd()
{
suppressRefresh = false;
}
Unfortunately this doesn't seem to be the case. Is there any other way to determine when the property grid is setting a property, or to otherwise achieve this same effect?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该类型在您的控制之下吗?您可以添加一对
FooUpdating
/FooUpdated
事件吗?另一种选择是使用 TypeDescriptionProvider 编写自定义属性模型,但我怀疑这会需要大量工作。我的第一次尝试是之前/之后对...类似于(更新以显示 3.5 方法;请参阅历史记录以了解 2.0 示例):
然后只需处理两个事件并根据需要启用/禁用更新。
Is the type under your control? You could add a
FooUpdating
/FooUpdated
pair of events? Another option would be to write a custom property-model withTypeDescriptionProvider
, but I suspect that would be quite a lot of work. My first attempt would be a before/after pair...Something like (updated to show 3.5 approach; see history for a 2.0 example):
Then just handle the two events and enable / disable updates as appropriate.