C# 中winForm 全屏与非全屏 切换闪动问题,大家有没有什么好的办法解决?为什么浏览器的全屏就不会很闪呢?1.
this.WindowState = FormWindowState.Normal; 
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized; 2.
if (this.FormBorderStyle == FormBorderStyle.None)
{
    this.FormBorderStyle = FormBorderStyle.FixedSingle;
    this.WindowState = FormWindowState.Normal;
}
else
{
    this.FormBorderStyle = FormBorderStyle.None;
    this.WindowState = FormWindowState.Maximized;
}代码类似如上。

解决方案 »

  1.   


            [DllImport("user32.dll", EntryPoint = "LockWindowUpdate")]
            public static extern int LockWindowUpdate(int hwndLock);
                        try
                {
                    LockWindowUpdate(this.Handle.ToInt32());
                    if (this.FormBorderStyle == FormBorderStyle.None)
                    {
                        this.FormBorderStyle = FormBorderStyle.FixedSingle;
                        this.WindowState = FormWindowState.Normal;
                    }
                    else
                    {
                        this.FormBorderStyle = FormBorderStyle.None;
                        this.WindowState = FormWindowState.Maximized;
                    }
                  
                }
                finally
                {
                    LockWindowUpdate(0);
                }
      

  2.   

        public partial class Form1 : Form
        {
            Rectangle selfRect = new Rectangle();
            public Form1()
            {
                InitializeComponent();
            }        private void button2_Click(object sender, EventArgs e)
            {
                Rectangle scrRect = new Rectangle(Screen.GetBounds(this).Location, Screen.GetBounds(this).Size);            this.SuspendLayout();
                if (this.FormBorderStyle == FormBorderStyle.FixedSingle)
                {
                    selfRect.Location = this.Location;
                    selfRect.Size = this.Size;
                    this.FormBorderStyle = FormBorderStyle.None;
                    this.Location = scrRect.Location;
                    this.Size = scrRect.Size;
                }
                else
                {
                    this.FormBorderStyle = FormBorderStyle.FixedSingle;
                    this.Location = selfRect.Location;
                    this.Size = selfRect.Size;
                }
                this.ResumeLayout(true);
            }
        }
    不是很熟悉C#,有些函数可能用的比较笨,但是能满足你的要求
      

  3.   

        public partial class Form1 : Form
        {
            Rectangle selfRect = new Rectangle();
            public Form1()
            {
                InitializeComponent();
            }        private void button2_Click(object sender, EventArgs e)
            {
                Rectangle scrRect = SystemInformation.WorkingArea;            scrRect.Height = scrRect.Height - 2;
                this.SuspendLayout();
                if (this.FormBorderStyle == FormBorderStyle.FixedSingle)
                {
                    selfRect.Location = this.Location;
                    selfRect.Size = this.Size;
                    this.FormBorderStyle = FormBorderStyle.None;
                    this.Location = scrRect.Location;
                    this.Size = scrRect.Size;
                }
                else
                {
                    this.FormBorderStyle = FormBorderStyle.FixedSingle;
                    this.Location = selfRect.Location;
                    this.Size = selfRect.Size;
                }
                this.ResumeLayout(false);
            }
      

  4.   

    感谢,LS的朋友,可能在简单的WinForm上你的方法是可行的,但是如果FORM上要加载许多东西的话,还是解决不了,this.ResumeLayout(false);还是true的时候好一些。
      

  5.   

    这个似乎没有什么太好的办法,要不你试试把Form的DoubleBuffered设置为True看是不是好点
      

  6.   

    别说可能,你尝试了没有,你可以想想IE或者遨游的全屏怎么做的
    不外乎就是改变窗口大小,然后重画里边的元素,这期间不要显示重画的过程,我想我的代码就是这个过程,有layout的2个函数也屏蔽了放大过程中控件的重画问题了。
    我认为成熟产品的解决方法就是我这种,只是考虑更详细更健壮而已。
    我认为我的代码就是控件很多的窗体也没有多少问题。
    其实你原来的代码闪烁严重主要还是,窗体改变border和最大化2个过程都要重画窗体,而且最大化,windows缺省有个动画过程,更加增强了你的闪烁感。
    我的代码正好这2个问题都解决了。
      

  7.   

    this.SetVisibleCore(false);
    this.WindowState = FormWindowState.Normal; 
    this.FormBorderStyle = FormBorderStyle.None; 
    this.WindowState = FormWindowState.Maximized;
    this.SetVisibleCore(true);
      

  8.   

    设置窗体的DoubleBuffered属性为true.