不错呦!smile@林凯西,确保“准备文件”中的几个文件都有安装,S...您好,看了您这篇帖子觉得很有帮助。但是有个问题想请...我的修改过了怎么还被恶意注册呢 @jjjjiiii 用PJ快9年了,主要是A...PJ3啊,貌似很少有人用PJ了,现在不是WP就是z...@332347365,我当时接入时错误码没有-10...楼主,ChkValue值应为-103是什么意思呢?...大哥 你最近能看到我发的信息,请跟我联系,我有个制...
WinForm版本升级器闪屏优化过程分享
编辑:dnawo 日期:2014-07-21
最近写了一个WinForm应用程序的版本升级器,测试发现没有新版本时升级器界面会一闪而过(闪屏),用户体验不好,于是想怎么解决这个问题。

升级器主要代码如下:
开始的思路是先把窗体隐藏起来,等确认升级时再显示窗体,修改,测试可以解决闪屏问题[1]:
还有没有其他解决方法?经分析,检测版本和From1窗体没什么关系,要是能先检测版本,确认升级时再初始化显示Form1窗体逻辑上更恰当,肯定也能解决闪屏问题,可以这么实现吗?可以,把检测过程移到应用程序入口函数即可,修改后的Program.cs如下:
这么改还有一个优点:完美解决了应用程序旧版本参数传入问题(从Main函数参数传入)。
补充说明
[1].在Form1_Load设置窗体属性this.Visible = false;或调用方法this.Hide();不能隐藏窗体;

升级器主要代码如下:
复制内容到剪贴板
程序代码

using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//1.检测版本
bool havNewVer = CheckNewVer();
//2.程序升级
if (havNewVer && MessageBox.Show("发现新版本:3.0,是否更新?", "更新", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
//todo
}
//3.退出应用程序
Application.Exit();
}
/// <summary>
/// 检测新版本
/// </summary>
/// <returns></returns>
private bool CheckNewVer()
{
return false;
}
}
}
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//1.检测版本
bool havNewVer = CheckNewVer();
//2.程序升级
if (havNewVer && MessageBox.Show("发现新版本:3.0,是否更新?", "更新", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
//todo
}
//3.退出应用程序
Application.Exit();
}
/// <summary>
/// 检测新版本
/// </summary>
/// <returns></returns>
private bool CheckNewVer()
{
return false;
}
}
}
开始的思路是先把窗体隐藏起来,等确认升级时再显示窗体,修改,测试可以解决闪屏问题[1]:
复制内容到剪贴板
程序代码

private void Form1_Load(object sender, EventArgs e)
{
//1.检测版本
bool havNewVer = CheckNewVer();
//2.程序升级
if (havNewVer && MessageBox.Show("发现新版本:3.0,是否更新?", "更新", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
//显示窗体(先在设计器设置窗体属性WindowState=Minimized,ShowInTaskbar=false)
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
//todo
}
//3.退出应用程序
Application.Exit();
}
{
//1.检测版本
bool havNewVer = CheckNewVer();
//2.程序升级
if (havNewVer && MessageBox.Show("发现新版本:3.0,是否更新?", "更新", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
//显示窗体(先在设计器设置窗体属性WindowState=Minimized,ShowInTaskbar=false)
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
//todo
}
//3.退出应用程序
Application.Exit();
}
还有没有其他解决方法?经分析,检测版本和From1窗体没什么关系,要是能先检测版本,确认升级时再初始化显示Form1窗体逻辑上更恰当,肯定也能解决闪屏问题,可以这么实现吗?可以,把检测过程移到应用程序入口函数即可,修改后的Program.cs如下:
复制内容到剪贴板
程序代码

using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(params string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1());
//1.检测版本
bool havNewVer = CheckNewVer();
//2.程序升级
if (havNewVer && MessageBox.Show("发现新版本:3.0,是否更新?", "更新", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
Application.Run(new Form1());
}
}
/// <summary>
/// 检测新版本
/// </summary>
/// <returns></returns>
static bool CheckNewVer()
{
return false;
}
}
}
using System.Collections.Generic;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(params string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1());
//1.检测版本
bool havNewVer = CheckNewVer();
//2.程序升级
if (havNewVer && MessageBox.Show("发现新版本:3.0,是否更新?", "更新", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
Application.Run(new Form1());
}
}
/// <summary>
/// 检测新版本
/// </summary>
/// <returns></returns>
static bool CheckNewVer()
{
return false;
}
}
}
这么改还有一个优点:完美解决了应用程序旧版本参数传入问题(从Main函数参数传入)。
补充说明
[1].在Form1_Load设置窗体属性this.Visible = false;或调用方法this.Hide();不能隐藏窗体;
评论: 0 | 引用: 0 | 查看次数: 2945
发表评论
请登录后再发表评论!