当前界面是一个设备状体监控界面(主窗体中的一个子窗体,设备刷新由主窗体实现),大概有1000左右的设备控件,所有控件均是自定义控件,界面可看到的大概200多个,当有窗体遮盖后,闪烁问题非常严重。     自定义控件已经设置了双缓冲,子窗体也做了如下设置
     
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer |
               ControlStyles.UserPaint |
               ControlStyles.AllPaintingInWmPaint,
               true);
            this.UpdateStyles();
    
请问应该怎么解决?一下是其中一个自定义控件的代码using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace UIKit
{
    public partial class Crane : UserControl
    {
        public Crane()
        {
            InitializeComponent();
        }        private string tankid = string.Empty;
        private string tanktype = string.Empty;
        private string tankcap = string.Empty;
        private string planload = string.Empty;
        private string pipe = string.Empty;
        private string deviceid = string.Empty; 
        private const string sTrue = "True";
        private const string sFalse = "False";
        private string subnumber;
        private bool isOnUse = false;        public bool IsOnUse
        {
            get { return isOnUse; }
            set { isOnUse = value; SetUserLight(value); }
        }        private void SetUserLight(bool value)
        {
            if(value==true)
            { pbUse.Image = global::UIKit.Properties.Resources.鹤位准备就绪; }
            else
            {pbUse.Image=global::UIKit.Properties.Resources.鹤位未使用;}
        }
            
        public string Subnumber
        {
            get { return lbListNum.Text; }
            set { subnumber = value; lbListNum.Text = value; }
        }        public string Tankid
        {
            get { return tankid; }
            set { tankid = value; lbTankid.Text = value; }
        }        public string Tanktype
        {
            get { return tanktype; }
            set { tanktype = value; lbtanktype.Text = value; }
        }        public string Tankcap
        {
            get { return tankcap; }
            set { tankcap = value; lbTankcap.Text = value; }
        }        public string Planload
        {
            get { return planload; }
            set { planload = value; lbPlanload.Text = value; }
        }        public string Pipe
        {
            get { return pipe; }
            set { pipe = value; lbPipe.Text = value; }
        }        public string DeviceId
        {
            get { return deviceid; }
            set { deviceid = value; }
        }        public string RealLoad
        { get { return lbRealload.Text; } }        public string Status
        { get { return lbStatus.Text; } }        private void SetStatustext(string text)
        {
            lbStatus.Text=text;
        }        private void SetRealLoad(string value)
        {
            lbRealload.Text = value;
        }        public delegate void SetTextHandler(string text);        public void SetStatus(string tag,string tagvalue)
        {
            //if (tag == "ready")
            //{
            //    if (tagvalue == sTrue)
            //    { craneReady = true; }
            //    if (tagvalue == sFalse)
            //    { craneReady = false; }
            //}
            if (tag == "status")
            {
                if (tagvalue == "0")
                { Invoke(new SetTextHandler(SetStatustext), "未装"); }
                if (tagvalue == "1")
                { Invoke(new SetTextHandler(SetStatustext), "待装"); }
                if (tagvalue == "2")
                { Invoke(new SetTextHandler(SetStatustext), "装车"); }
                if (tagvalue == "3")
                { Invoke(new SetTextHandler(SetStatustext), "完毕"); }
         
            }
            //if (tag == "end")
            //{
            //    if (tagvalue == sTrue)
            //    { Invoke(new SetTextHandler(SetStatustext), "结束"); }
            //}
            if (tag == "realload")
            {
                Invoke(new SetTextHandler(SetRealLoad),tagvalue );
            }
        }        public delegate void CraneRunEventHandler(object sender,string deviceid);        public delegate void CraneNumberGetEventHandler(string msg);        public event CraneRunEventHandler RunEvent;        public event CraneRunEventHandler ResetEvent;        public event CraneRunEventHandler ShowSingleEvent;        public void ClearInfo()
        {
            this.deviceid = "";
            this.isOnUse = false;
            SetUserLight(false);            pbStart.Enabled = true;
            pbReset.Image = global::UIKit.Properties.Resources.复位合;            this.lbListNum.Text = string.Empty;
            this.lbPipe.Text = string.Empty;
            this.lbPlanload.Text = string.Empty;
            this.lbRealload.Text = string.Empty;
            this.lbStatus.Text = string.Empty;
            this.lbStatus.Text = string.Empty;
            this.lbTankcap.Text = string.Empty;
            this.lbtanktype.Text = string.Empty;
        }        private void pbReset_Click(object sender, EventArgs e)
        {
            if (lbStatus.Text == "正在装")
            {
                if (MessageBox.Show("当前正在发油中,确认要复位吗?", "注意!", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    ResetEvent(this,this.deviceid);
                }
                else
                { return; }
            }
            else
            {
                ResetEvent(this,this.deviceid);
            }
        }        private void pbStart_Click(object sender, EventArgs e)
        {
            if (lbStatus.Text != "待装")
            {
                MessageBox.Show("鹤位未就绪,不能发油!");
            }
            else
            {
                RunEvent(this,this.deviceid);
            }
        }        private void pbInfo_Click(object sender, EventArgs e)
        {
            ShowSingleEvent(this,this.deviceid);
        }
    }
}

解决方案 »

  1.   


    private void newToolStripMenuItem_Click(object sender, EventArgs e)
            {
                User32.LockWindowUpdate(this.Handle);
                L3Form frm =(L3Form) new MdiForm(m_oAppBridge.MainInterface);
                frm.MdiParent = this;
                frm.ShowIcon = false;
                //frm.ControlBox = true;
                
                frm.Text = "Child-" + this.MdiChildren.Length.ToString();
                frm.Show();
                User32.LockWindowUpdate(IntPtr.Zero);
            }上面是我用过的方法,希望对你有用
      

  2.   

    [DllImport("User32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            public static extern bool LockWindowUpdate(IntPtr hwnd);
      

  3.   

    补充一下,我在在主窗体初始化的时候就将所有子窗体载入了,显示各子窗体的时候用bringtofront()显示
      

  4.   

    自定义控件的构造函数里加上:
    public partial class Crane : UserControl
        {
            public Crane()
            {
                InitializeComponent();
    //这里加上
    base.SetStyle(ControlStyles.OptimizedDoubleBuffer,true);
    base.SetStyle(ControlStyles.UserPaint ,true);
    base.SetStyle(ControlStyles.AllPaintingInWmPaint,true);
            }
      

  5.   

    LZ把你界面样子发我看看,如果可以源码最好.
    [email protected]