C# WinForm - loading screen -
i ask how make loading screen (just picture or something) appears while program being loaded, , disappears when program has finished loading.
in fancier versions, have seen process bar (%) displayed. how can have that, , how calculate % show on it?
i know there form_load() event, not see form_loaded() event, or % property / attribute anywhere.
all need create 1 form splash screen , show before main start showing landing page , close splash once landing page loaded.
class splashform { //delegate cross thread call close private delegate void closedelegate(); //the type of form displayed splash screen. private static splashform splashform; static public void showsplashscreen() { // make sure launched once. if (splashform != null) return; thread thread = new thread(new threadstart(splashform.showform)); thread.isbackground = true; thread.setapartmentstate(apartmentstate.sta); thread.start(); } static private void showform() { splashform = new splashform(); application.run(splashform); } static public void closeform() { splashform.invoke(new closedelegate(splashform.closeforminternal)); } static private void closeforminternal() { splashform.close(); } ... }
and main program function looks this:
[stathread] static void main(string[] args) { splashform.showsplashscreen(); mainform mainform = new mainform(); //this takes ages splashform.closeform(); application.run(mainform); }
Comments
Post a Comment