C#:覆盖 DataGridView 滚动条(自定义 OnPaint)?

发布于 2024-10-08 00:50:08 字数 264 浏览 9 评论 0原文

我有一个继承自 DataGridView 的用户控件。我已经重写了 OnRowPrePaint、OnRowPostPaint、OnCellPaint 和其他一些内容,这样我就可以根据需要绘制整个内容。除了滚动条之外,一切都运行得很漂亮。如何拦截正在绘制的滚动条并绘制自己的滚动条?

理想情况下,有一些数据结构包含滚动条本身的边界以及实际滚动滑块的边界。然后我就可以在这些位置的图形层上绘图。

有办法做到这一点吗?似乎其他一切都已考虑在内,所以我想有某种方法可以做到这一点......

I have a usercontrol that inherits from a DataGridView. I have overridden OnRowPrePaint, OnRowPostPaint, OnCellPaint, and some others so I can draw the entire thing as I want. Everything works beautifully, except the scrollbars. How can I intercept the scrollbars being painted and paint my own?

Ideally there is some datastructure that contains the bounds for the scroll bar itself as well as the bounds for actually scroll-slider. Then I can just draw on the graphics layer at those locations.

Is there a way to do this? It seems like everything else was though of, so I would imagine there is some way to do it...

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

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

发布评论

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

评论(2

汹涌人海 2024-10-15 00:50:08

从滚动条类继承时,将其添加到 Sub New:

Me.SetStyle(ControlStyles.UserPaint, True)

OnPaint 事件现在将触发。

要覆盖单击控件时绘制的标准按钮/滑块:

Me.SetStyle(ControlStyles.UserMouse, True)

并减少闪烁:

Me.SetStyle(ControlStyles.AllPaintingInWmPaint, False)

编辑:

我显然需要学习阅读。

没有注意到

继承自 a 的用户控件
数据网格视图

位......

When inheriting from the scrollbar class, add this to Sub New:

Me.SetStyle(ControlStyles.UserPaint, True)

The OnPaint event will now fire.

To override the standard buttons / slider from being drawn when clicking the control:

Me.SetStyle(ControlStyles.UserMouse, True)

And to reduce the flicker:

Me.SetStyle(ControlStyles.AllPaintingInWmPaint, False)

EDIT:

I clearly need to learn to read.

Didn't notice the

usercontrol that inherits from a
DataGridView

bit........

守护在此方 2024-10-15 00:50:08

首先想到的是:使用滚动条中的绘制事件。无论如何,滚动条都是从 Control 派生的。可能不是最佳解决方案...

public class MyDGV : DataGridView
{
    this.VerticalScrollBar.Paint += new PaintEventHandler(VerticalScrollBar_Paint);
}

void VerticalScrollBar_Paint(object sender, PaintEventArgs e)
{
    // Paint stuff
}

First thing that comes to mind: use the paint events from the scrollbars. The scrollbars are derived from Control anyway. Might not be the optimum solution...

public class MyDGV : DataGridView
{
    this.VerticalScrollBar.Paint += new PaintEventHandler(VerticalScrollBar_Paint);
}

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