The most recent version of the WinForm application was a release upgrade, the test found that when no new version of the upgrade interface will flash over (splash screen), the user experience is not good, so how to solve the problem.
The main code for the upgrade is as follows:
| The code is as follows |
Copy Code |
|
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. Test version
BOOL Havnewver = Checknewver ();
2. Program upgrades
if (Havnewver && MessageBox.Show ("Found new version: 3.0, update?") "," Update ", Messageboxbuttons.yesno, messageboxicon.information) = = Dialogresult.yes)
{
Todo
}
3. Exit Application
Application.exit ();
}
<summary>
Detecting a new version
</summary>
<returns></returns>
private bool Checknewver ()
{
return false;
}
}
}
|
The beginning of the idea is to hide the form first, and so on to confirm the upgrade and then display the form, modify, test can solve the splash screen problem [1]:
| code is as follows |
copy code |
|
Private void Form1_Load (object sender, EventArgs e)
{
//1. Detection version
bool Havnewver = Checknewver ();
//2. Program Upgrades
if (havnewver && MessageBox.Show ("Discover new version: 3.0, update? "," Update ", Messageboxbuttons.yesno, messageboxicon.information) = = Dialogresult.yes)
{
//Display form (first set form properties in designer Windowstate=minimized,showintaskbar=false)
this. WindowState = Formwindowstate.normal;
this. ShowInTaskbar = true;
//todo
}
//3. Exit Application
Application.exit ();
} |
Is there any other way out? After analysis, the detection version and FROM1 form does not matter, if you can detect the version first, confirm the upgrade and then initialize the display Form1 form logically more appropriate, will also be able to solve the splash screen problem, can this be achieved? You can move the detection process to the application entry function, and the modified Program.cs is as follows:
| The code is as follows |
Copy Code |
|
Using System;
Using System.Collections.Generic;
Using System.Windows.Forms;
Namespace WindowsFormsApplication1
{
static class program
{
& nbsp; ///<summary>
/// The main entry point for the application.
///</summary>
[STAThread]
static void Main (params string[] args)
{
Application.enablevisualstyles ();
Application.setcompatibletextrenderingdefault (FALSE);
//application.run (New Form1 ());
//1. Detection version
bool Havnewver = Checknewver ();
//2. Program Upgrades
if (havnewver && MessageBox.Show ("Found new version: 3.0, update?") "," Update ", Messageboxbuttons.yesno, messageboxicon.information) = = Dialogresult.yes)
{
Application.Run (New Form1 ());
}
}
<summary>
Detecting a new version
</summary>
<returns></returns>
static bool Checknewver ()
{
return false;
}
}
}
|
One of the advantages of this change is that it solves the problem of passing the old version parameter of the application (passed in from the main function parameter).
Supplementary notes
[1]. Set the form property This.visible = False in Form1_Load, or call method this. Hide (); Cannot hide form;