绘制边框在某些情况下运行

发布于 2024-08-21 23:31:38 字数 776 浏览 7 评论 0原文

在我的工具中,我使用面板来更改页面。每个页面都有自己的面板,当我更改页面时,我会发送带有控件的面板。在我用作画布的面板上,我有以下绘制事件:

    private void panelContent_Paint(object sender, PaintEventArgs e)
    {
        e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
        e.Graphics.SmoothingMode = SmoothingMode.HighQuality;

        // Paints a border around the panel to match the treeview control
        e.Graphics.DrawRectangle(Pens.CornflowerBlue,
            e.ClipRectangle.Left,
            e.ClipRectangle.Top,
            e.ClipRectangle.Width - 1,
            e.ClipRectangle.Height - 1);

        e.Graphics.Flush();

        base.OnPaint(e);
    }

此方法基本上在面板周围绘制了一个漂亮的边框,因此看起来更好。由于某种原因,当我在该面板上方移动另一个表单时,构成边框的线条开始稍微移动。偶尔也会从边框绘制小线。该问题仅发生几秒钟,然后整个面板再次重绘。我能做些什么来防止这种情况发生吗?

In my tool I use a a panel to change pages. Each page has it's own panel and when I change a page I send the panel with the controls. On the panel I use as the canvas I have the following paint event:

    private void panelContent_Paint(object sender, PaintEventArgs e)
    {
        e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
        e.Graphics.SmoothingMode = SmoothingMode.HighQuality;

        // Paints a border around the panel to match the treeview control
        e.Graphics.DrawRectangle(Pens.CornflowerBlue,
            e.ClipRectangle.Left,
            e.ClipRectangle.Top,
            e.ClipRectangle.Width - 1,
            e.ClipRectangle.Height - 1);

        e.Graphics.Flush();

        base.OnPaint(e);
    }

This method basically draws a nice border around the panel so it look better. For some reason when I move a another form above this panel the lines that make up the border start to run a little. Occasionally small lines will be drawn from the border too. The problem only happens for a few seconds before the entire panel redraws again. Is there anything I can do to prevent this from happening?

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

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

发布评论

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

评论(1

独闯女儿国 2024-08-28 23:31:38

ClipRectangle 告诉您控件的哪一部分需要重新绘制。如果您要在其上移动某物,则这可能是您的物体与被移动的物体的交集。您可以使用此信息更有效地重新绘制控件。

您可能想要绘制从 (0, 0) 到 (panelContent.Width-1, panelContent.Height-1) 的矩形。

ClipRectangle tells you what part of the control needs to be repainted. If you're moving something over it, this is probably going to be the intersection of your object and the one being moved. You can use this information to more efficiently repaint your control.

You probably want to draw the rectangle from (0, 0) to (panelContent.Width-1, panelContent.Height-1).

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