如何确定控件当前是否失效?
我正在编写一个托管控件的自定义 DataGridView
单元格类。 我正在侦听 Invalidated
事件,以了解是否应该重新定位和重新绘制单元格,但我遇到了循环,因为重新定位单元格可能会使其他托管单元格无效,从而使第一个单元格无效,并且很快。 我不想使用静态成员来避免循环,因为这不会阻止由相似但不相关的单元类引起的循环(如果它们一起使用)。 所以我需要检查网格当前是否失效。 我怎么做?
I'm writing a custom DataGridView
cell class that hosts a control. I'm listening to the Invalidated
event to know whether I should reposition and repaint the cell, but I'm getting loops because repositioning the cell can invalidate other hosted cells, which then invalidate the first one, and so on. I don't want to use a static member to avoid loops, because that won't prevent loops caused by similar but unrelated cell classes, if they were ever used together. So I need to check whether the grid is currently invalidating. How do I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不必“监听”无效事件。 当用户控件失效时,onpaint 会自动调用。
可能有更好的方法来解决您的最终问题(绘制自定义数据网格视图)。 您可以尝试发布有关您的实施的详细问题,并询问一些如何实施的想法,这样您就不必解决这些(看似奇怪的)问题。
You shouldn't have to 'listen' to the invalidated event. When a user control invalidates, onpaint gets called automatically.
There might be a better way to go about solving your ultimate problem (wrt painting your custom datagridview). You could try posting a detailed question about your implementation and asking for some ideas of how to go about it such that you wouldn't have to work around these (seemingly strange) problems.
听起来您想重写 DataGridViewCell 类的 Paint 成员,而不是尝试侦听和响应 Invalidated 事件。 基类将为您处理这些问题,并将图形对象和位置信息直接提供给 Paint 方法
It sounds like you want to override the Paint member of the DataGridViewCell class, rather than try to listen and respond to Invalidated events. The base class will take care of that for you and provide the graphics object and location information directly to the Paint method