如何确定控件当前是否失效?

发布于 2024-07-15 08:59:37 字数 234 浏览 11 评论 0原文

我正在编写一个托管控件的自定义 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 技术交流群。

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

发布评论

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

评论(2

等风也等你 2024-07-22 08:59:37

您不必“监听”无效事件。 当用户控件失效时,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.

萌︼了一个春 2024-07-22 08:59:37

听起来您想重写 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

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