Splash Screen Fade app causing main app to flutter.

G

Guest

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.tmrFadeIn)).BeginInit();
//
// tmrFadeIn
//
this.tmrFadeIn.Interval = 20;
this.tmrFadeIn.SynchronizingObject = this;
this.tmrFadeIn.Elapsed += new
System.Timers.ElapsedEventHandler(this.tmrFade_Elapsed);
//
// 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.CenterScreen;
((System.ComponentModel.ISupportInitialize)(this.tmrFadeIn)).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
 
G

Guest

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 said:
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.tmrFadeIn)).BeginInit();
//
// tmrFadeIn
//
this.tmrFadeIn.Interval = 20;
this.tmrFadeIn.SynchronizingObject = this;
this.tmrFadeIn.Elapsed += new
System.Timers.ElapsedEventHandler(this.tmrFade_Elapsed);
//
// 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.CenterScreen;
((System.ComponentModel.ISupportInitialize)(this.tmrFadeIn)).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());
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top