Hi

I'm creating a multiple form GUI app using a scene-manager to set the current visible form.

There isn't an issue regarding it working, that's fine. What I am noticing is that when each form is set to be active/visible, it takes a few seconds to load each component, and looks horrid. This is potentially for a business related endeavor, so I'm looking for a way to buffer the form so it loads fully before it is displayed.

I'm not sure if this is an issue with the use of a scene-manager, or it is something that is consistent across all C# form applications.

I've done a few google searches relating to this, but there was little aside from using "hide()" until it was loaded. That doesn't really work.

Any information would be great

Hi Dekken, welcome here!
perhaps you could use the DoubleBuffered property of the form by setting it to true.

if you are referring to the controls on the form, suspend and resume layout methods of the forms class tells the form not to bother painting the controls until its finished creating them, but I don't know about this scene manager you speak of, so it may not support suspendlayout or resumelayout.

Create a new windows forms application project in visual studio and then drag some buttons onto the form from the tool box, then in the solution expand the item for Form1 and open Form1.Designer.cs notice that in the initializecomponents method defined there that before any controls are added this.suspendLayout() is called. Then after each control is added this.resumeLayout() is called. This prevents the display from acting crazy until all the controls are successfully added.

Hope this helps.

>>There isn't an issue regarding it working, that's fine. What I am noticing is that when each form is set to be active/visible, it takes a few seconds to load each component, and looks horrid. This is potentially for a business related endeavor, so I'm looking for a way to buffer the form so it loads fully before it is displayed.

Using hide until it is loaded won't really work. When you "make a form visible" or "make a control visible" it will fire the Load event for that control/form. It uses a delayed initialization, I forget the MS terminology for it. This way the application doesn't expense creating controls that will never show.

That being said what Diamonddrake told you is true. The designer should stop controls from showing until everything is ready to render with ISupportInitialize.BeginInit() . I can't think of a scenario like this and I have forms withs lots of controls.

Perhaps you could upload a demo project demonstrating this behavior?

... use the DoubleBuffered property ...

That seems to have done something, thank you very much.

if you are referring to the controls on the form, suspend and resume layout methods of the forms class tells the form not to bother painting the controls until its finished creating them, but I don't know about this scene manager you speak of, so it may not support suspendlayout or resumelayout.

Create a new windows forms application project in visual studio and then drag some buttons onto the form from the tool box, then in the solution expand the item for Form1 and open Form1.Designer.cs notice that in the initializecomponents method defined there that before any controls are added this.suspendLayout() is called. Then after each control is added this.resumeLayout() is called. This prevents the display from acting crazy until all the controls are successfully added.

Hope this helps.

Thanks for the post, forms are still created in the usual way, I've made not change to the automated form creation, so suspend/resume aer still there.

That being said what Diamonddrake told you is true. The designer should stop controls from showing until everything is ready to render with ISupportInitialize.BeginInit() . I can't think of a scenario like this and I have forms withs lots of controls.

Perhaps you could upload a demo project demonstrating this behavior?

Sure. I'm not sure what I've done, but it seems to have been quashed somewhat. The forms load faster, but there's still a flicker.

I think it was originally something to do with the images I was using as buttons, they were PNGs. it seemed like they were loading after the form as already displayed. It's still happening, but it's much quicker now.

//Main Program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using BPM_C_Sharp_Touchscreen.Scenes;

namespace BPM_C_Sharp_Touchscreen
{
    class Program
    {
        private static SceneManager sceneManager;

        public static SceneManager SceneManager
        {
            get { return sceneManager; }
        }

        public Program()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            sceneManager = new SceneManager();
            SceneManager.addScene(new Home());
            SceneManager.selectScene("Home");

            Application.Run(sceneManager);
        }


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

//SceneManager
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections.Generic;

namespace BPM_C_Sharp_Touchscreen
{
    public class SceneManager : ApplicationContext
    {
        private List<Form> forms = new List<Form>();
        protected bool exitAppOnClose;

        public void selectScene(string scene)
        {            
            foreach (Form f in forms)
            {
                if ((f.Name).Equals(scene))
                {
                    if (MainForm != null)
                        MainForm.Hide();
                    MainForm = f;
                    MainForm.Show();
                }
            }
        }

        public void addScene(Form toAdd)
        {
            forms.Add(toAdd);
        }

        public void removeScene(Form toRemove)
        {
            forms.Remove(toRemove);
        }

        // when a form is closed, don't exit the application if this is a swap
        protected override void OnMainFormClosed(object sender, EventArgs e)
        {
            if (exitAppOnClose)
            {
                base.OnMainFormClosed(sender, e);
            }
        }

        //Getters and setters
        public List<Form> Forms
        {
            get
            {
                return forms;
            }
            set
            {
                forms = value;
            }
        }
    }
}
This article has been dead for over six months. Start a new discussion instead.