473,387 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Splash Screen Fade app causing main app to flutter.

Can someone look at this and tell me why, when I call this from my main app,
it displays fine (fades form in and out) but then before my main app
displays, I see other dialog boxes flash monentarily on the screen and this
delays the main app display?

Here is the fade which I compile to a dll and call from my main app:

using System;
using System.Threading;
using System.Timers;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace SplashScreenBasic
{
/// <summary>
/// Summary description for Basic Splash Form.
/// </summary>
public class Splash : System.Windows.Forms.Form
{
protected internal System.Timers.Timer tmrFadeIn;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Splash()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this.Opacity = 0;
this.Show();
tmrFadeIn.Enabled = true;

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

/// <summary>
/// Call from static methods.
/// </summary>
[STAThread]
public static void ShowForm()
{
Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new Splash());
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(Splash));
this.tmrFadeIn = new System.Timers.Timer();
((System.ComponentModel.ISupportInitialize)(this.t mrFadeIn)).BeginInit();
//
// tmrFadeIn
//
this.tmrFadeIn.Interval = 20;
this.tmrFadeIn.SynchronizingObject = this;
this.tmrFadeIn.Elapsed += new
System.Timers.ElapsedEventHandler(this.tmrFade_Ela psed);
//
// Splash
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackgroundImage =
((System.Drawing.Image)(resources.GetObject("$this .BackgroundImage")));
this.ClientSize = new System.Drawing.Size(384, 184);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "Splash";
this.Opacity = 0;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScree n;
((System.ComponentModel.ISupportInitialize)(this.t mrFadeIn)).EndInit();

}
#endregion

private void Splash_Load(object sender, System.EventArgs e)
{

}
///Splash screen
///Fade out/in
///Called from form constructor.
private bool upflag = true;
private void tmrFade_Elapsed(object sender, System.Timers.ElapsedEventArgs
e)
{
if (this.Opacity < 1 && upflag == true)
{
this.Opacity += 0.05;
}
if (this.Opacity >= 1)
{
upflag = false;
Thread.Sleep(4000);
this.tmrFadeIn.Interval = 5;
}
if (upflag == false)
{
this.Opacity -= 0.025;
}
if (this.Opacity <= 0 && upflag == false)
{
tmrFadeIn.Enabled = false;
SplashScreenBasic.Splash.ActiveForm.Close();
}
}
}
}

Here is the main app:

#region Using directives
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using SplashScreenBasic;

#endregion

namespace FileNames2TXT
{

/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;
//
public Form1()
{
//
// Required for Windows Form Designer support
//
SplashScreenBasic.Splash.ShowForm();
InitializeComponent();
// TODO: Add any constructor code after InitializeComponent call
//
// Constructor.
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button3 = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(40, 104);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(104, 23);
this.button1.TabIndex = 0;
this.button1.Text = "Select Source";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(184, 104);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(120, 23);
this.button2.TabIndex = 1;
this.button2.Text = "Select Destination";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// folderBrowserDialog1
//
this.folderBrowserDialog1.Description = "Select Directory";
this.folderBrowserDialog1.SelectedPath = "G:\\";
this.folderBrowserDialog1.ShowNewFolderButton = false;
//
// saveFileDialog1
//
this.saveFileDialog1.AddExtension = false;
this.saveFileDialog1.CheckPathExists = false;
this.saveFileDialog1.DereferenceLinks = false;
this.saveFileDialog1.OverwritePrompt = false;
this.saveFileDialog1.ValidateNames = false;
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(312, 16);
this.label1.TabIndex = 2;
this.label1.Text = "Select file directory and text file.";
//
// label2
//
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.label2.Location = new System.Drawing.Point(8, 48);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(312, 16);
this.label2.TabIndex = 3;
this.label2.Tag = "";
//
// button3
//
this.button3.Location = new System.Drawing.Point(128, 152);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(72, 23);
this.button3.TabIndex = 4;
this.button3.Text = "OK";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(328, 189);
this.Controls.Add(this.button3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "FileNames2TXT";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
///
[STAThread]
static void Main(string[] args)
{
Application.Run(new Form1());
}

private string folderName1, fileName1 ;

public void button1_Click(object sender, System.EventArgs e) //open folder
selection.
{
DialogResult result = folderBrowserDialog1.ShowDialog();
if(result == DialogResult.OK ) //folder selected
{
folderName1 = folderBrowserDialog1.SelectedPath;
label1.Text = folderName1 ;
}
else
{
folderName1 = null ;
label1.Text = "Select file folder." ;
}
}

public void button2_Click(object sender, System.EventArgs e)
{
saveFileDialog1.Filter = "txt files (*.txt)|*.txt" ; //display dialog
saveFileDialog1.OverwritePrompt = true ;
saveFileDialog1.ValidateNames = true ;
saveFileDialog1.InitialDirectory = "g:\\lsptemp" ;
saveFileDialog1.RestoreDirectory = true ;
saveFileDialog1.CheckFileExists = false ; //will not add
..ext if true.
saveFileDialog1.DereferenceLinks = false ;
saveFileDialog1.AddExtension = true ;
saveFileDialog1.DefaultExt = "TXT" ;
DialogResult result2 = saveFileDialog1.ShowDialog();
if (result2 == DialogResult.OK )
{
fileName1 = saveFileDialog1.FileName;
label2.Text = fileName1 ;
}
else
{
fileName1 = null ;
label2.Text = "Select a text file." ;
}
}

public void button3_Click(object sender, System.EventArgs e) //Okay button
{
if (folderName1 != null && fileName1 != null)
{
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(folderName1);
StreamWriter writer = new StreamWriter(fileName1);
foreach (System.IO.FileInfo file in dir.GetFiles("*.*"))
{
writer.WriteLine(" {0}", file.FullName);
}
writer.Close();
MessageBox.Show("File names from: \n" +
folderName1 +
"\n "
+ "\n Written to: \n"
+ fileName1);

Application.Exit();
}
}

private void Form1_Load(object sender, System.EventArgs e)
{
}
} //end form1 class
} //end namespace

Thanks for any direction.

Bill
Nov 17 '05 #1
1 3576
I think I found the problem.

Instead of using this line: SplashScreenBasic.Splash.ActiveForm.Close();

I replaced it with: this.Close();

And it seems to work fine.

Thanks for any trouble.

Bill

"BillZondlo" wrote:
Can someone look at this and tell me why, when I call this from my main app,
it displays fine (fades form in and out) but then before my main app
displays, I see other dialog boxes flash monentarily on the screen and this
delays the main app display?

Here is the fade which I compile to a dll and call from my main app:

using System;
using System.Threading;
using System.Timers;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace SplashScreenBasic
{
/// <summary>
/// Summary description for Basic Splash Form.
/// </summary>
public class Splash : System.Windows.Forms.Form
{
protected internal System.Timers.Timer tmrFadeIn;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Splash()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this.Opacity = 0;
this.Show();
tmrFadeIn.Enabled = true;

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

/// <summary>
/// Call from static methods.
/// </summary>
[STAThread]
public static void ShowForm()
{
Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new Splash());
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(Splash));
this.tmrFadeIn = new System.Timers.Timer();
((System.ComponentModel.ISupportInitialize)(this.t mrFadeIn)).BeginInit();
//
// tmrFadeIn
//
this.tmrFadeIn.Interval = 20;
this.tmrFadeIn.SynchronizingObject = this;
this.tmrFadeIn.Elapsed += new
System.Timers.ElapsedEventHandler(this.tmrFade_Ela psed);
//
// Splash
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackgroundImage =
((System.Drawing.Image)(resources.GetObject("$this .BackgroundImage")));
this.ClientSize = new System.Drawing.Size(384, 184);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "Splash";
this.Opacity = 0;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScree n;
((System.ComponentModel.ISupportInitialize)(this.t mrFadeIn)).EndInit();

}
#endregion

private void Splash_Load(object sender, System.EventArgs e)
{

}
///Splash screen
///Fade out/in
///Called from form constructor.
private bool upflag = true;
private void tmrFade_Elapsed(object sender, System.Timers.ElapsedEventArgs
e)
{
if (this.Opacity < 1 && upflag == true)
{
this.Opacity += 0.05;
}
if (this.Opacity >= 1)
{
upflag = false;
Thread.Sleep(4000);
this.tmrFadeIn.Interval = 5;
}
if (upflag == false)
{
this.Opacity -= 0.025;
}
if (this.Opacity <= 0 && upflag == false)
{
tmrFadeIn.Enabled = false;
SplashScreenBasic.Splash.ActiveForm.Close();
}
}
}
}

Here is the main app:

#region Using directives
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using SplashScreenBasic;

#endregion

namespace FileNames2TXT
{

/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;
//
public Form1()
{
//
// Required for Windows Form Designer support
//
SplashScreenBasic.Splash.ShowForm();
InitializeComponent();
// TODO: Add any constructor code after InitializeComponent call
//
// Constructor.
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button3 = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(40, 104);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(104, 23);
this.button1.TabIndex = 0;
this.button1.Text = "Select Source";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(184, 104);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(120, 23);
this.button2.TabIndex = 1;
this.button2.Text = "Select Destination";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// folderBrowserDialog1
//
this.folderBrowserDialog1.Description = "Select Directory";
this.folderBrowserDialog1.SelectedPath = "G:\\";
this.folderBrowserDialog1.ShowNewFolderButton = false;
//
// saveFileDialog1
//
this.saveFileDialog1.AddExtension = false;
this.saveFileDialog1.CheckPathExists = false;
this.saveFileDialog1.DereferenceLinks = false;
this.saveFileDialog1.OverwritePrompt = false;
this.saveFileDialog1.ValidateNames = false;
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(312, 16);
this.label1.TabIndex = 2;
this.label1.Text = "Select file directory and text file.";
//
// label2
//
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.label2.Location = new System.Drawing.Point(8, 48);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(312, 16);
this.label2.TabIndex = 3;
this.label2.Tag = "";
//
// button3
//
this.button3.Location = new System.Drawing.Point(128, 152);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(72, 23);
this.button3.TabIndex = 4;
this.button3.Text = "OK";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(328, 189);
this.Controls.Add(this.button3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "FileNames2TXT";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
///
[STAThread]
static void Main(string[] args)
{
Application.Run(new Form1());
}

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: andrewcw | last post by:
I implemented the simplest of splash screens ( static and on its own thread ). But it seem that when first called maybe 8 seconds elapsed before it showed up, the main form follows several seconds...
2
by: Stuart Ferguson | last post by:
Hi, I am currently writing a GUI which requires a splash screen in C#, the form itself has a Graphic (Inside a picture box) and 2 labels on it, when i show it using the following the form soesnt...
14
by: SStory | last post by:
I am trying to make a splash screen for my vb.net app. It is an mdi app. including the splash code produces wierd results. not inluding makes things fine. Also have tried loading the splash...
4
by: Lou | last post by:
Ok, How can I have my main app initialize while showng a splash screen. -Lou
1
by: Ken Allen | last post by:
I am developing a small utility program that must perform a considerable amount of 'background' or 'research' work before it can display any user interface. In general it can take 3-15 seconds to...
7
by: Bob | last post by:
I have a winforms app written in Vs2005 Vb.Net, The setiings are to Enable the application Framework and I defined a splashform. Works fine if no errors occur. I do a checking on the mainform load...
2
by: will_456 | last post by:
In vb2005 Express: In My Project Application Splash Screen I have selected my splash screen form. The form opens on project startup but closes immediately before anyone would have time to read...
10
by: =?Utf-8?B?UmljaGFyZCBCeXNvdXRo?= | last post by:
Hi In my app I have a SplashScreen, a login form and a main form. On launching the app, I'd like to show the SplashScreen while reading config files and attempting a database connection. I show...
4
by: Gaz | last post by:
I am having a bit of a problem getting my application to work properly. RIght here is my problem... WHen my C# windows app loads up the start form, i create a new thread and show the splash...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.