为什么我的表格不锁起来? [英] Why does my form NOT lock up?

查看:179
本文介绍了为什么我的表格不锁起来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读从另一个问题我是100%肯定,下面的code会锁定这个答案的UI和不会引起任何移动。

While reading this answer from another question I was 100% sure that the following code would lock up the UI and not cause any movement.

private void button1_Click(object sender, EventArgs e)
{
    for (int i = 0; i < 5; i++)
    {
        this.Left += 10;
        System.Threading.Thread.Sleep(75);
        this.Left -= 10;
        System.Threading.Thread.Sleep(75);
    }
}

我和其他几个人在评论中说,这是行不通的,但OP坚持认为它确实和我们应该尝试。最后我做一个新的WinForms项目,添加一个按钮,然后把上面的code。在事件处理程序的点击和形式的确动摇。

I and several others in the comments said it would not work but the OP insisted that it did and we should try. I ended up making a new Winforms project, adding a button, then putting the above code in the event handler for click and the form did indeed shake.

如何在窗体移动时消息泵被阻止通过这种方法,OnPaint中不应该是能够被称为形式或任何其子控件上,这是怎么工作?

How is the form moving when the message pump is being blocked by this method, OnPaint should not be able to be called on the form nor any of its child controls, how is this working?

推荐答案

航空做到这一点。窗口不直呈现到所述视频帧缓冲区了,它们渲染到存储器。想想位图。 DWM的过程中再复合这些位图,并将其位块传输到缓冲区。这解决了一些窗口绘制的文物中,最臭名昭著的一次是可能的小道你当跨过另一移动一个窗口留下。无论进程所拥有的底部窗口已经赶上并重绘显示像素。这需要时间,未上漆的像素,其中可见。也允许其他的特殊效果,如实时缩略图,你可以看到,当你在一个任务栏按钮悬停,仅仅是位图的副本缩小到适合。而且航空皮克,该位只是一个投影。而玻璃在Vista和Win7的。而特殊的屏幕,其中存储的应用程序显示在Win8中。而当你触摸屏幕,你看到的明显痕迹。

Aero does this. Windows don't render straight to the video frame buffer anymore, they render to memory. Think "bitmap". The DWM process then composites these bitmaps and blits them to the buffer. This solves a number of window painting artifacts, the most infamous one was probably the "trail" you'd leave behind when moving one window across another. Whatever process owned the bottom window had to catch up and repaint the revealed pixels. That takes time and the unpainted pixels where visible. Also allows for other special effects, like the live thumbnails you can see when you hover over a taskbar button, simply a copy of that bitmap shrunk to fit. And Aero Peek, just a projection of that bitmap. And glass in Vista and Win7. And the special "screen" where Store apps are displayed in Win8. And the visible marks you see when you touch the screen.

和影响此code,以及,窗口位置,现在仅仅是一个不同的位置,对位图进行合成。原始位图仍然完好无损,并且不需要重新油漆

And affects this code as well, the window position is now simply a different location where the bitmap is composited. The original bitmap is still intact and doesn't require repainting.

不要尝试这种在XP或航空关闭。

Don't try this on XP or with Aero turned off.

这篇关于为什么我的表格不锁起来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆