Вы находитесь на странице: 1из 20

loading advertisement ...

Start FREE Trial


Contact Us
Member Login
Top of Form
1

Username or Email:

Password:Forgot your password?

Remember Me
Do not use on any shared computer
/Programming/Lan

Cancel
Login
Bottom of Form
Experts Exchange
Ask
Solutions
Articles
Testimonials
Blogs
Help
Top of Form

Google EE
1 Google Search 315 / Enter Your 1
Advanced
Bottom of Form
Home
Programming
Prog Languages
C#
C# - Loading screen for Form
 
lrmoore
angelIII
leew
eoinosullivan
sirbounty
PC Magazine Press Release
Business Clients: IBM, Toyota, Comcast, American Express
PCWorld Press Release
Business Clients: ESPN, Adobe, Microsoft, ebay
Wired Press Release
 
 
Advertisement
 

Hall of Fame
1. roshmon498,778
2. tgerbert394,494
3. kris_per379,267
4. guru_sami378,088
5. Idle_Mind342,633
6. kaufmed324,172
7. Fernando...314,066
8. mas_oz...280,145
9. carl_tawn278,062
10. TheLearn...240,669
11. anarki_ji...218,771
12. SriVaddadi176,494
13. lazyberez...159,030
14. k_swapnil155,587
15. zadeveloper149,703
16. sedgwick146,970
17. masterpass140,705
18. cyberkiwi140,354
19. Dhaest137,087
20. nmarun131,499
21. rkworlds124,494
22. vs00saini123,853
23. w00te118,912
24. djjaries116,999
25. Mathiyazh...113,303
1. TheLearn...2,948,000
2. gregoryyo...1,422,807
3. jaime_oliv...1,410,501
4. Idle_Mind1,380,247
5. Fernando...1,346,266
6. AlexFM994,109
7. anarki_ji...968,474
8. ragi0017889,064
9. angelIII786,405
10. gauthampj761,115
11. dstanley9713,657
12. Dhaest706,111
13. abel666,862
14. TheAvenger653,871
15. carl_tawn648,900
16. emoreau632,136
17. JimBrandley596,614
18. kaufmed577,132
19. guru_sami552,310
20. tgerbert549,001
21. roshmon518,100
22. mas_oz...480,559
23. p_davis460,730
24. Zephyr__442,269
25. MogalManic441,087
 

[x]
Posted via EE Mobile
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from
your mobile device and never be out of touch again.

Question

[x]
Attachment Details

[x]
The Solution Rating System
With so many solutions, how can you tell which solutions are most likely to help you and which
ones are not? To provide you with a tool to use, we rate our solutions based on various elements
that most accurately determine if a solution is a quality solution. To explain what factors affect the
solution rating, here are the elements we take into consideration when formulating our solution
rating.
The Grade of the Solution
The Zone Rank of the Expert Providing the Solution
The Number of Author and Expert Comments
The Number of Experts Contributing
The Feedback of the Community
Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a
member of Experts Exchange, you are able to cast your vote on the quality of the solutions in
regard to how complete, accurate, helpful and easy to understand each solution is. When you
provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor
rating that you think is a good solution, let us know by rating it. As you do, the rating will be
adjusted and will become more accurate for other members of our site.
If you have any suggestions that you would like to make for our rating system, please ask a
question in the Suggestions Zone of Community Support.
Thank you!

7.0

C# - Loading screen for Form


Asked by Cyber-Drugs in C# Programming Language
Tags: screen, loading
Hi guys 'n gals,

I have a Form with a heck of a lot of Form_OnLoad() function calls, which basically means it's a good 5-
10 seconds before the Form is usable. I wanted to know if it is possible to display a little Form/Picture in
the absolute middle/middle of the Form (on top of all controls), which states the form is loading, and
disables clicking of anything on the form. Once it is loaded, the Form/Picture is removed and clicking is
re-enabled for the Form.

Is this possible? If so, how would I go about doing this?

Cheers!
This question has been solved and asker verified.
All Experts Exchange premium technology solutions are available to subscription members.
Subscribe now for full access to Experts Exchange and get
INSTANT ACCESS TO THIS SOLUTION
Plus...
30 Day FREE access, no risk, no obligation
Collaborate with the world's top tech experts
Unlimited access to our exclusive solution database
Never be left without tech help again

 
Zone: C# Programming Language
Tags: screen, loading
Solution Provided By: C_Sharp_Programmer
Participating Experts: 1
Solution Grade: A
 
 
 

Top Solutions
Keywords: C# - Loading screen for Form
Title
1 Mod funtion in c#?
2 Better way to remove special characters from a string
3 Reading an Excel file in C#
4 C# using Message.box == DialogResult.Yes and…
5 SendMessage API in C# - Sending a mouse click to …
6 send mail using smtp in c#

 
Loading Advertisement...
 
 
Loading Advertisement...
 

Microsoft
Internet Protocols
Microsoft OS
MS Applications
MS Development
MS Forefront-ISA
MS Hardware
MS Server Apps
Apple
Apple Hardware
Apple OS
Apple Programming
Apple Software
Networking
Internet
Anti-Spyware
Anti-Virus
AntiSpam Software
Chat / IM
Email Clients
File Sharing Software
Internet Development
New Net Users
Search Engines
Web Browsers
Web Servers
WebTrends / Stats
Gamers
Action / Adventure
Computer Games
Game Consoles
Game Emulators
Game Programming
Game Tips/Tricks
Misc Games
MMORPG Games
Digital Living
Apple Digital Living
Automotive
Digital Living Hardware
Digital Living Software
Digital Music
Gaming World
Home Security
Networking Hardware
New Computer Users
New Net Users
Virus & Spyware
Anti-Spyware
Anti-Virus
AntiSpam Software
Cell Phones
Encryption
Hardware Firewalls
HijackThis
IDS
Internet Security
Latest Threats
OS Security
Software Firewalls
Vulnerabilities
Web Applications
Hardware
Apple Hardware
Desktops
Displays / Monitors
Embedded Hardware
Handhelds / PDAs
Hardware Components
Laptops/Notebooks
Misc Hardware
Networking Hardware
New Computer Users
Peripherals
Server Hardware
Storage
Software
Business Management
CYGWIN
Database
Development Software
Firewalls
Industry Specific
Internet / Email Software
Message Queue
Misc Software
MultiMedia Applications
Network Management
Office / Productivity
OS
OS / 2 Apps
Page Layout Software
Photos / Graphics Soft.
Quality Assurance
Security Software
Server Software
System Utilities
Virtualization
VMware
Voice Recognition
Web Development
ITPro
Anti-Spyware
Anti-Virus Apps
AntiSpam Software
Apple Hardware
Chat / IM
Consulting
Displays / Monitors
Email Clients
Encryption
File Sharing Software
Firewalls
Hardware Components
IDS
IT Administration
Laptops/Notebooks
Networking
Networking Hardware
OS
OS Security
Peripherals
Search Engines
Server Hardware
Storage
Vulnerabilities
Web Applications
Web Browsers
Web Servers
Web/Cloud Computing
WebTrends / Stats
Developer
Application Servers
Content Management
CYGWIN
Database
Dev Tools
File Sharing Software
Game Programming
Industry Specific
Networking Protocols
Office / Productivity
Programming
Search Engines
Web Browsers
Web Development
Web Servers
WebTrends / Stats
Storage
Backup / Restore
Disaster Recovery
Grid
Hard Drives
Remote Access
Removable Backup Media
Server Hardware
Storage Misc
Storage Technology
OS
Apple OS
AS-400 OS
BeOS
Google Chrome OS
Linux
MainFrame OS
Microsoft OS
Misc OS
OS / 2
OS Development
OS Security
Unix OS
VMS / OpenVMS
VMware
Database
4GL
Contact Management
Data Manipulation
DB Reporting Tools
DB2
dBase
Enterprise Software
Filemaker Pro
FoxPro
GIS & GPS
Health Care/MUMPS
Informix
Interbase / Firebird
LDAP
Misc Databases
MS Access
MS SQL Server
MySQL Server
OLAP
Oracle Database
PostgreSQL
SAS
Sybase Database
Unify SQLBase
Security
Anti-Spyware
Anti-Virus
AntiSpam Software
Chat / IM
Digital Forensics
Email Clients
Encryption
File Sharing Software
IDS
Internet Security
Misc Security
OS Security
Software Firewalls
VPN
Vulnerabilities
Web Applications
Web Browsers
Programming
Algorithms
Automation
Database
Editors IDEs
Game Programming
Handheld/PDA Prog
Misc Installation
Misc Programming
Multimedia Programming
Open Source
Processor Platforms
Prog Languages
Programming Theory
Project Management
Signal Processing
System Programming
Web Development
Authoring
Blogs
Digital Camera Software
Document Imaging
Fonts
Illustration Software
Images & Photo Software
Internet Marketing
Misc Web Dev
Scripting Languages
Search Engines
Web Applications
Web Components
Web Dev Software
Web Frameworks
Web Graphics Software
Web Images
Web Languages/Standards
Web Servers
Web Services
Web-Based CMS
WebTrends / Stats
Networking
Apple Networking
Application Servers
Backup / Restore
Broadband
Content Management
Email Servers
File Servers
Grid
ISPs & Hosting
Java Editors & IDEs
Linux Networking
Message Queue
Misc Networking
Network Management
Network Security
Networking Hardware
Networking Protocols
Novell Netware
OS / 2 Networking
OS Networking
Removable Backup Media
Server Hardware
Storage Technology
System Utilities
Telecommunications
Unix Networking
Web Servers
Web/Cloud Computing
Windows Networking
Wireless Networking
Other
Automotive
Business Travel
Community Support
Expert Lounge
Hot URLs
Lounge
Math / Science
Miscellaneous
New Net Users
Philosophy / Religion
Politics
Puzzles / Riddles
Community Support
Announcements
Article Tips
Beta Feedback
CleanUp
EE Bugs
Feedback
General
Input
New to EE
New Zones
Suggestions
 
 

 
C_Sharp_Programmer:
How about a splash screen instead?

Create a form without a border (name it Splash and make sure the class definition reads
      public class Splash : System.Windows.Forms.Form)

Add any image you want to it.

Add a progress bar (always useful to the user) and name it progMain

Add the following code to the form:

      #region Variables
      static int total = 100;
      static int currPos = 0;

        static string text;


 
        // Threading
            static Splash ms_frmSplash = null;
            static Thread ms_oThread = null;
        #endregion

        #region Properties
        public int TotalValue
            {
                  get
                  {
                        return total;
                  }
                  set
                  {
                        total = value;
                        progMain.Maximum = total;
                  }
            }

            public int Progress


            {
                  get
                  {
                        return currPos;
                  }
                  set
                  {
                        currPos = value;
                        try
                        {
                              progMain.Value = currPos;
                        }
                        catch {}
                  }
            }
            #endregion

            static public void ShowSplashScreen()


            {
                  // Make sure it's only launched once.
                  if( ms_frmSplash != null )
                        return;
                  ms_oThread = new Thread( new ThreadStart(Splash.ShowForm));
                  ms_oThread.IsBackground = true;
                  ms_oThread.Start();
            }

            // A property returning the splash screen instance


            static public Splash SplashForm
            {
                  get
                  {
                        return ms_frmSplash;
                  }
            }
            // A private entry point for the thread.
            static private void ShowForm()
            {
                  ms_frmSplash = new Splash();
                  Application.Run(ms_frmSplash);
            }

On your main form, put this code at the TOP of the load event:        
             this.Hide();
            Splash mySplash = new Splash();
            mySplash.TotalValue = 25; //or however many steps you must complete
            mySplash.Show();

whenever you finish part of your load code, just use the
          mySplash.Progress++;

to advance the progress bar on your splash screen.

At the end of the load event, use:


            mySplash.Dispose();
            this.Show();

You should be good to go!  Is this a help?


 
 
Cyber-Drugs:
Looks like it would do the trick, except I have a problem here:

static Thread ms_oThread = null;

"Thread" is not in my list, I only have "ThreadExceptionDialog"

Do I need to include something at the top of the Form to allow this?


 

 
Cyber-Drugs:
using System.Threading;

Nevermind, found it, just trying the rest of the code now
 
 
Cyber-Drugs:
That is a lot better, but it takes the Splash screen a good second or two to display, when it's actually just
a blank form (at the moment, soon will add a picture) and a progress bar.

The form loads instantly, but the progress bar is blank for a second, and then it appears. The rest is
beautiful though, any idea about that progress bar issue?
 

 
C_Sharp_Programmer:
I'll check on this for you! (I'm at work right now)
 
 
Cyber-Drugs:
Ok cheers! :o)
 

 
C_Sharp_Programmer:
Ok, I tried this on my machine and the progress bar is visible immediately.  Here is the code I used to
test it (located in the form load event):

            this.Hide();
            Splash mySplash = new Splash();
            mySplash.TotalValue = 10000;
            mySplash.Show();
            for (int i = 0; i < 10000; i++)
      {
                this.Text = i.ToString();
                mySplash.Progress = i;
      }
            mySplash.Dispose();
            this.Show();

So, you're saying that the splash screen appears, but the progress bar isn't there?
 
 
Cyber-Drugs:
Ok, I've fix for the progress bar, basically it needed to be redrawn, so I added an extra value to the max,
and before the first function call, increased the progress bar by 1 (thus re-drawing it). But I am still
having the problem of Form1 flashing for a second before displaying the Spash Screen.

Is it possible to have Form1 display itself as hidden before it even draws itself, thus avoiding the flash?

Cheers!
 

 
C_Sharp_Programmer:
Again, I can't seem to duplicate the problem on my machine, but try these:

1. call the 'this.hide()' method at the top of the form constructor.

2. set the form's visibility to false in the designer.  Then set it to visible before calling the .show() method
at the end of the load event.

Does this help?  If not, I'll keep looking!


 
 
Cyber-Drugs:
Unfortunately it still flashes, is it maybe possible to set the default first load form to the Splash screen,
and then load up Form1 as visible in the background, and once everything is loaded, show Form1 and
hide the Splash screen?
 

 
C_Sharp_Programmer:
Sorry, I was on the wrong track all together!  You are using VS 2005?  if so, open the program.cs file and
modify the Main function like so:

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());  NOTE: This line has been commented out!
            Form1 f1 = new Form1(); //or whatever your main form is called
            f1.doStuff();
            Application.Run(f1);
Now add the doStuff() method to your form (you can call this method whatever you wish).  move all of
your code from the load event to the doStuff() method.  This SHOULD cause your form to execute all
required code before actually painting anything.  You should also notice an increase in speed....  Let me
know if this works for you!
 
 
C_Sharp_Programmer:
You can also remove the .Hide() and .Show() methods for your main form as well now....
 

 
Cyber-Drugs:
Ok, excuse my ignorance, but why does my function not show up in the list of functions associated with
Form1?

I'm using:

public void PreLoad() {}

Also, just to clarify, I am using Visual Studio 2005.


 
 
C_Sharp_Programmer:
did you add the function to your Form1 code?  Make sure and add it there and not in the Program.cs
file.  
 

 
Cyber-Drugs:
It is inside Form1, and I have clicked SaveAll to make sure it registeres properly, but it's not showing up,
a bit confusing.
 
 
C_Sharp_Programmer:
in the Program.cs file, are you accessing the function as f1.PreLoad()? (where f1 is whatever you named
your Form1).  Make sure you aren't trying to access it using Form1.PreLoad(), as this won't work (unless
you make the function static, which I probably wouldn't do in this case).
 

 
Cyber-Drugs:
           Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());
            Form f1 = new Form1();
            f1.PreLoad();
            Application.Run(f1);

"PreLoad" is underlined in blue, and when I try compile I get this error:

'System.Windows.Forms.Form' does not contain a definition for 'PreLoad'


 
 
C_Sharp_Programmer:
Ok, we'll get that squared away!  Change this line:

Form f1 = new Form1();

to this:

Form1 f1 = new Form1();  //use Form1, not Form

It's a mistake I have made many times in the past!  Let me know if it works for you!
 

 
Cyber-Drugs:
Brilliant, works a charm, thank you! :o)
 
 
C_Sharp_Programmer:
Any time!  Glad I could help!
 

 
Cyber-Drugs:
I've just created a new question, related to this, in case you may be interested:

http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_22555594.html
 
 
20100802-EE-VQP-174
Shorten URL|
Help|
About Us|
Contact Us|
Terms of Use|
EE Blog|
Internet Rank|
Privacy Policy|
Site Map
Copyright © 1996 - 2010 Experts Exchange, LLC. All rights reserved.

Вам также может понравиться