c# winfrom 更新控件时停止刷新,解决闪烁问题
static Dictionary<Control, bool> m_lstFreezeControl = new Dictionary<Control, bool>(); /// <summary> /// 功能描述:停止更新控件 /// </summary> /// <param name="control">control</param> /// <param name="blnToFreeze">是否停止更新</param> public static void FreezeControl(Control control, bool blnToFreeze) { if (blnToFreeze && control.IsHandleCreated && control.Visible && !control.IsDisposed && (!m_lstFreezeControl.ContainsKey(control) || (m_lstFreezeControl.ContainsKey(control) && m_lstFreezeControl[control] == false))) { m_lstFreezeControl[control] = true; control.Disposed += control_Disposed; HZCX.Controls.Controls.NativeMethods.SendMessage(control.Handle, 11, 0, 0); } else if (!blnToFreeze && !control.IsDisposed && m_lstFreezeControl.ContainsKey(control) && m_lstFreezeControl[control] == true) { m_lstFreezeControl.Remove(control); HZCX.Controls.Controls.NativeMethods.SendMessage(control.Handle, 11, 1, 0); control.Invalidate(true); } } static void control_Disposed(object sender, EventArgs e) { try { if (m_lstFreezeControl.ContainsKey((Control)sender)) m_lstFreezeControl.Remove((Control)sender); } catch { } }
使用方法
try { HZCX.Controls.ControlHelper.FreezeControl(this, true); //你的更新界面操作 } finally { HZCX.Controls.ControlHelper.FreezeControl(this, false); }
作者:冰封一夏
出处:http://www.cnblogs.com/bfyx/
HZHControls官网:http://www.hzhcontrols.cn
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,
且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
GitHub:https://github.com/kwwwvagaa/NetWinformControl
码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git