将区域应用于表单时出现问题

发布于 2024-08-01 19:50:27 字数 676 浏览 6 评论 0原文

当我将非矩形区域应用于 Windows 窗体(比如说椭圆形)时,我遇到了奇怪的行为。 问题是,在最初调整大小时,表单似乎消失了一段时间(就好像该区域是空的)。 它看起来像是轻微的闪烁,而表单后面的桌面内容在几分之一秒内变得可见。 第一次调整大小后,不再观察到这种闪烁。

这可以通过简单地创建一个 Windows 窗体项目并通过使用窗体的大小作为椭圆的边界矩形将椭圆区域应用到窗体来重现(通过这种方式,您将能够调整窗体的大小,因此其边框不会改变)被该地区完全“吃掉”)。

注意:我正在 OnResize 事件中更新表单的区域。

我正在使用的代码如下所示:

 protected override void OnResize(EventArgs e)
 {
     base.OnResize(e);
     GraphicsPath path = new GraphicsPath();
     path.AddEllipse(new Rectangle(Point.Empty, this.Size));

     this.Region = new Region(path);
 }

有什么想法可能导致此问题吗?

快速跟进:

我注意到,当我将相同的代码片段放入 OnSizeChanged 事件中时,闪烁消失或似乎很少发生。

谢谢!

I am facing a strange behavior when I apply a non-rectangular region to a Windows Form (lets say an ellipse). The issue is that the form seems to disappear for a moment (as if the region is empty) when initially resized. It looks like a slight flicker whereas the contents of the desktop behind the form become visible for a fraction of the second. After the first resize this flicker is no longer observable.

This can be reproduced by simply creating a Windows Forms project and applying an ellipse region to the form by using the size of the form as a bounds rectangle for the ellipse (in this way you will be able to resize the form hence its borders will not be completely "eaten" by the region).

Note: I am updating the region of the Form in the OnResize event.

The code that I am using looks the following way:

 protected override void OnResize(EventArgs e)
 {
     base.OnResize(e);
     GraphicsPath path = new GraphicsPath();
     path.AddEllipse(new Rectangle(Point.Empty, this.Size));

     this.Region = new Region(path);
 }

Any ideas what might be causing this?

Quick follow-up:

I noticed that when I put the same code snippet in the OnSizeChanged event the flicker disappears or seems to happen rarely.

Thanks!

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

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

发布评论

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

评论(2

画骨成沙 2024-08-08 19:50:27

处理绘制事件

private void Form1_Paint(object sender, PaintEventArgs e)
{
GraphicsPath path = new GraphicsPath(); 
path.AddEllipse(new Rectangle(Point.Empty, this.Size)); 
this.Region = new Region(path); 
}

Handles Paint event

private void Form1_Paint(object sender, PaintEventArgs e)
{
GraphicsPath path = new GraphicsPath(); 
path.AddEllipse(new Rectangle(Point.Empty, this.Size)); 
this.Region = new Region(path); 
}
夏日落 2024-08-08 19:50:27

您在同一领域为我解决了一个大问题。

我正在使用这个:

    private void BorderedPanel_SizeChanged(object sender, EventArgs e)
    {
        this.Region = new Region(RoundedRectangle.CreatePlusOne(this.ClientRectangle, this.cornerRadius, this.RectangleCorners));
        Refresh();
    }

它工作时不会闪烁。 所以值得一试!

You've fixed a massive problem for me in the same area.

I'm using this:

    private void BorderedPanel_SizeChanged(object sender, EventArgs e)
    {
        this.Region = new Region(RoundedRectangle.CreatePlusOne(this.ClientRectangle, this.cornerRadius, this.RectangleCorners));
        Refresh();
    }

and it works without flickering. So it's worth giving a shot!

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