kenlistian

勤学多思

  IT博客 :: 首页 :: 新随笔 ::  :: 聚合  :: 管理 ::
  138 随笔 :: 0 文章 :: 23 评论 :: 0 Trackbacks

 

1.屏幕由于拖动闪动或者是切换界面时出现闪动时,直接对form的DoubleBuffered设置双缓冲刷新即可解决.

//form窗体类
  this.DoubleBuffered = true;  //减少屏幕闪动

 

2.对于拖动窗体造成窗体中的控件闪动,也可以调用user.dll的api函数来处理.

[DllImport("user32.dll")]
static extern bool LockWindowUpdate(IntPtr hWndLock);
 
//该api暂停某个控件的展现
//在控件绘制之前暂停展示,在绘制完毕之后再显示出来。


//例子:当缩放的时候解决闪烁问题:
// 解决后的现象是,整个form1只出现一次闪烁,没有了疯狂的刷新了。
void form1_ResizeBegin(object sender, EventArgs e)
{
        LockWindowUpdate(this.Handle);
} 
  
void form1_ResizeEnd(object sender, EventArgs e)
{
            LockWindowUpdate(IntPtr.Zero);
}

 

 

3.

A form that has a lot of controls takes a long time to paint. Especially the Button control in its default style is expensive. Once you get over 50 controls, it starts getting noticeable. The Form class paints its background first and leaves "holes" where the controls need to go. Those holes are usually white, black when you use the Opacity or TransparencyKey property. Then each control gets painted, filling in the holes. The visual effect is ugly and there's no ready solution for it in Windows Forms. Double-buffering can't solve it as it only works for a single control, not a composite set of controls. I discovered a new Windows style in the SDK header files, available for Windows XP and (presumably) Vista: WS_EX_COMPOSITED. With that style turned on for your form, Windows XP does double-buffering on the form and all its child controls.

source:http://social.msdn.microsoft.com/forums/en-US/winforms/thread/aaed00ce-4bc9-424e-8c05-c30213171c2c/

protected override CreateParams CreateParams 

{ 

get 

{ 

CreateParams cp = base.CreateParams; 

cp.ExStyle |= 0x02000000; 

return cp; 

} 

} 

 
posted on 2013-05-09 14:16 kenlistian 阅读(1436) 评论(0)  编辑 收藏 引用 所属分类: csharp
只有注册用户登录后才能发表评论。