将区域应用于表单时出现问题
当我将非矩形区域应用于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
处理绘制事件
Handles Paint event
您在同一领域为我解决了一个大问题。
我正在使用这个:
它工作时不会闪烁。 所以值得一试!
You've fixed a massive problem for me in the same area.
I'm using this:
and it works without flickering. So it's worth giving a shot!