首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

WINFORM 自己写的全屏事件 有办法避免全屏的过程中窗体闪烁吗?该如何解决

2014-01-01 
WINFORM 自己写的全屏事件 有办法避免全屏的过程中窗体闪烁吗?首先相关代码:private void control_magnify

WINFORM 自己写的全屏事件 有办法避免全屏的过程中窗体闪烁吗?
首先相关代码:


        private void control_magnify(double fw, double fh)//按长宽比例变动调整控件位置 放大用
        {
            int x;
            int y;
            x = Convert.ToInt32(panel1.Size.Width * fw);
            panel1.Size = new Size(x, panel1.Size.Height);
            //x = Convert.ToInt32(panel2.Location.X * fw);
            //y = Convert.ToInt32(panel2.Location.Y * fh);
            //panel2.Location = new Point(x, y);
            x = Convert.ToInt32(panel2.Size.Width * fw);
            y = Convert.ToInt32(panel2.Size.Height * fh);
            panel2.Size = new Size(x, y);
            //x = Convert.ToInt32(panel3.Location.X * fw);
            //y = Convert.ToInt32(panel3.Location.Y * fh);
            //panel3.Location = new Point(x, y);
            x = Convert.ToInt32(panel3.Size.Width * fw);
            y = Convert.ToInt32(panel3.Size.Height * fh);
            panel3.Size = new Size(x, y);
            
            foreach (Control ctl in this.Controls)
            {
                x = Convert.ToInt32(ctl.Location.X * fw);
                y = Convert.ToInt32(ctl.Location.Y * fh);
                ctl.Location = new Point(x, y);
            }
            foreach (Control ctl in this.panel2.Controls)
            {
                if (ctl is PictureBox)
                {
                    x = Convert.ToInt32(ctl.Location.X * fw);
                    y = Convert.ToInt32(ctl.Location.Y * fh);
                    ctl.Location = new Point(x, y);
                }
            }
            foreach (Control ctl in this.panel3.Controls)
            {
                if (ctl is PictureBox)
                {
                    x = Convert.ToInt32(ctl.Location.X * fw);
                    y = Convert.ToInt32(ctl.Location.Y * fh);
                    ctl.Location = new Point(x, y);
                }
            }
        }
        private void control_minify(double fw, double fh)//按长宽比例变动调整控件位置 缩小用
        {
            int x;
            int y;


            x = Convert.ToInt32(panel1.Size.Width / fw);
            panel1.Size = new Size(x, panel1.Size.Height);
            
            x = Convert.ToInt32(panel2.Size.Width / fw);
            y = Convert.ToInt32(panel2.Size.Height / fh);
            panel2.Size = new Size(x, y);
            //x = Convert.ToInt32(panel3.Location.X / fw);
            //y = Convert.ToInt32(panel3.Location.Y / fh);
            //panel3.Location = new Point(x, y);
            x = Convert.ToInt32(panel3.Size.Width / fw);
            y = Convert.ToInt32(panel3.Size.Height / fh);
            panel3.Size = new Size(x, y);
            foreach (Control ctl in this.Controls)
            {
                x = Convert.ToInt32(ctl.Location.X / fw);
                y = Convert.ToInt32(ctl.Location.Y / fh);
                ctl.Location = new Point(x, y);
            }
            foreach (Control ctl in this.panel2.Controls)
            {
                if (ctl is PictureBox)
                {
                    x = Convert.ToInt32(ctl.Location.X / fw);
                    y = Convert.ToInt32(ctl.Location.Y / fh);
                    ctl.Location = new Point(x, y);
                }
            }
            foreach (Control ctl in this.panel3.Controls)
            {
                if (ctl is PictureBox)
                {
                    x = Convert.ToInt32(ctl.Location.X / fw);
                    y = Convert.ToInt32(ctl.Location.Y / fh);
                    ctl.Location = new Point(x, y);
                }
            }
        }
        private void FullScreen_Click(object sender, EventArgs e)//“全屏”按钮事件
        {
            double w = this.Size.Width;
            double h = this.Size.Height;
            fw = SW / w;
            fh = SH / h;
            this.FormBorderStyle = FormBorderStyle.None;
            this.WindowState = FormWindowState.Maximized;
            this.KeyPreview = true;
            this.KeyUp += new KeyEventHandler(Form2_KeyUp);
            control_magnify(fw, fh);


            FullScreen.Click -= new EventHandler(FullScreen_Click);
        }
        private void Form2_KeyUp(object sender, KeyEventArgs e)//ESC退出全屏
        {
            if (e.KeyCode == Keys.Escape) //“Esc” 按键退出全屏
            {
                this.FormBorderStyle = FormBorderStyle.FixedDialog;
                this.WindowState = FormWindowState.Normal;
                control_minify(fw, fh);
                this.KeyUp -= new KeyEventHandler(Form2_KeyUp);
                FullScreen.Click += new EventHandler(FullScreen_Click);
            }
        }



全屏和退出全屏时控件的大小位置都很好照我的想法变动了 问题是在向全屏变动的过程中 窗体内控件会有1秒左右的时间在闪烁 有没有办法避免这个闪烁呢?

[解决办法]
双缓冲,先放在image里,再贴图。
[解决办法]
http://stackoverflow.com/questions/487661/how-do-i-suspend-painting-for-a-control-and-its-children

试试这个,临时禁止重绘,全屏后重启启用绘制
[解决办法]
引用:
Quote: 引用:

http://stackoverflow.com/questions/487661/how-do-i-suspend-painting-for-a-control-and-its-children

试试这个,临时禁止重绘,全屏后重启启用绘制

是直接调用类方法吧?没有多大作用 该闪照闪...就是闪得不那么厉害了

我这边试着事件响应时先this.hide() 调整完毕后在this.show()
不闪烁了 不过问题就是退出全屏时窗体大小没有改变...调整了this.Size和this.ClientSize也一样....



你要是想改变Size的话,你应该在SizeChange里做工作代码呀
[解决办法]


 [DllImport("user32.dll")]
        private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
        private const int AW_HOR_POSITIVE = 0x0001;//从左到右打开窗口
        private const int AW_HOR_NEGATIVE = 0x0002;//从右到左打开窗口
        private const int AW_VER_POSITIVE = 0x0004;//从上到下打开窗口
        private const int AW_VER_NEGATIVE = 0x0008;//从下到上打开窗口
        private const int AW_CENTER = 0x0010;//从中央打开
        private const int AW_HIDE = 0x10000;//隐藏窗体
        private const int AW_ACTIVATE = 0x20000;//显示窗体
        private const int AW_SLIDE = 0x40000;
        private const int AW_BLEND = 0x80000;//淡入淡出效果


//调用

AnimateWindow(this.Handle, 5, AW_VER_NEGATIVE);



哦...对不起,我把其他的代码都写进去了,其他的代码是:调用摄像头的一样API声明,对于你问题有用的是上边那些.

热点排行