C#关于Windows窗体最大化所引起的闪烁问题的处理经验
来源:互联网 发布:武林外传演员现状 知乎 编辑:程序博客网 时间:2024/06/05 05:59
1:窗体最大化前,窗体最好没有任何控件在显示,并且控件不要有背景图,等窗体最大化后才显示控件以及加载背景图。
2:最大化源码(从网上搜回来的:)
using System;using System.Windows.Forms;using System.Drawing;using System.Runtime.InteropServices;namespace XXXX.Definition{ public class WinApi { [DllImport("user32.dll", EntryPoint = "GetSystemMetrics")] public static extern int GetSystemMetrics(int which); [DllImport("user32.dll")] public static extern void SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter, int X, int Y, int width, int height, uint flags); private const int SM_CXSCREEN = 0; private const int SM_CYSCREEN = 1; private static IntPtr HWND_TOP = IntPtr.Zero; private const int SWP_SHOWWINDOW = 64; // 0x0040 public static int ScreenX { get { return GetSystemMetrics(SM_CXSCREEN); } } public static int ScreenY { get { return GetSystemMetrics(SM_CYSCREEN); } } public static void SetWinFullScreen(IntPtr hwnd) { SetWindowPos(hwnd, HWND_TOP, 0, 0, ScreenX, ScreenY, SWP_SHOWWINDOW); } } /// <summary> /// Class used to preserve / restore state of the form /// </summary> public class FormState { private FormWindowState winState; private FormBorderStyle brdStyle; private bool topMost; private Rectangle bounds; private bool isMaximized = false; public bool IsMaximized { get { return isMaximized; } } public void Maximize(Form targetForm) { if (!isMaximized) { targetForm.SuspendLayout(); isMaximized = true; Save(targetForm); targetForm.WindowState = FormWindowState.Maximized; targetForm.FormBorderStyle = FormBorderStyle.None; targetForm.TopMost = false; WinApi.SetWinFullScreen(targetForm.Handle); targetForm.ResumeLayout(true); } } public void Save(Form targetForm) { targetForm.SuspendLayout(); winState = targetForm.WindowState; brdStyle = targetForm.FormBorderStyle; topMost = targetForm.TopMost; bounds = targetForm.Bounds; targetForm.ResumeLayout(true); } public void Restore(Form targetForm) { targetForm.WindowState = winState; targetForm.FormBorderStyle = brdStyle; targetForm.TopMost = topMost; targetForm.Bounds = bounds; isMaximized = false; } }}
下面是使用的代码:
/// <summary> /// 正常的窗体状态 /// </summary> public FormState FrmState=new FormState();//窗体点击esc时切换 private void MaxForm_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 27) if (FrmState.IsMaximized) FrmState.Restore(this); else FrmState.Maximize(this); }下面要留意的,就是闪烁问题的,大家留意下:
窗体的Shown事件:
private void frm_Main_Shown(object sender, EventArgs e) { this.Visible = false; FrmState.Maximize(this); this.Visible = true; //加载背景图 AutoLoadBackImage(); }其实,窗体闪烁严重的在于窗体有很多控件或者是存在背景图。因此,在最大化前必须让窗体处于控件量最小,没有背景图的情况。在最大化后再对控件以及背景图进行加载。
原创作品出自努力偷懒,转载请说明文章出处:http://blog.csdn.net/kfarvid或 http://www.cnblogs.com/kfarvid/
- C#关于Windows窗体最大化所引起的闪烁问题的处理经验
- C#编写Windows窗体程序最大化引起的闪烁总结
- 关于c# winForm窗体最大化的设置
- 关于c# winForm窗体最大化的设置
- 关于c# winForm窗体最大化的设置
- 窗体闪烁的问题
- QT 无边框窗体最大化 遮挡windows任务栏的问题
- C# 显示窗体显示是闪烁的问题
- 解决Windows 程序界面闪烁问题的一些经验
- 解决Windows 程序界面闪烁问题的一些经验 (转载)
- 解决Windows 程序界面闪烁问题的一些经验
- 解决Windows 程序界面闪烁问题的一些经验 (转载)
- 解决Windows 程序界面闪烁问题的一些经验(zt)
- 解决Windows 程序界面闪烁问题的一些经验
- 解决Windows 程序界面闪烁问题的一些经验
- 解决Windows 程序界面闪烁问题的一些经验
- 解决Windows 程序界面闪烁问题的一些经验
- 解决Windows 程序界面闪烁问题的一些经验
- 百度java/db/jQuery/Ajax/javascript群
- DsoFramer.ocx制作CAB包详细图解过程
- 浅析linux中鼠标数据读取
- C++中的临时对象
- 如何为u盘设置背景图片
- C#关于Windows窗体最大化所引起的闪烁问题的处理经验
- 23种设计模式一语概括
- java类的生命周期
- Linux内核Makefile文件
- 概述MVC体系结构 为什么要用MVC结构?
- Test ehcache
- Axis2开发问题与解决
- ASP.NET MVC3的伪静态实现
- AndroidManifest.xml文件解析