C# Multi-form pre-render?

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2009
Posts: 2
Reputation: Dekken is an unknown quantity at this point 
Solved Threads: 0
Dekken Dekken is offline Offline
Newbie Poster

C# Multi-form pre-render?

 
0
  #1
19 Days Ago
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,908
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 273
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso
 
0
  #2
19 Days Ago
Hi Dekken, welcome here!
perhaps you could use the DoubleBuffered property of the form by setting it to true.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 318
Reputation: Diamonddrake is a jewel in the rough Diamonddrake is a jewel in the rough Diamonddrake is a jewel in the rough 
Solved Threads: 38
Diamonddrake's Avatar
Diamonddrake Diamonddrake is offline Offline
Posting Whiz
 
0
  #3
18 Days Ago
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,187
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
0
  #4
18 Days Ago
>>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?
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 2
Reputation: Dekken is an unknown quantity at this point 
Solved Threads: 0
Dekken Dekken is offline Offline
Newbie Poster
 
0
  #5
18 Days Ago
Originally Posted by ddanbe View Post
... use the DoubleBuffered property ...
That seems to have done something, thank you very much.

Originally Posted by Diamonddrake View Post
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.

Originally Posted by sknake View Post
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.

  1. //Main Program
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Windows.Forms;
  6. using BPM_C_Sharp_Touchscreen.Scenes;
  7.  
  8. namespace BPM_C_Sharp_Touchscreen
  9. {
  10. class Program
  11. {
  12. private static SceneManager sceneManager;
  13.  
  14. public static SceneManager SceneManager
  15. {
  16. get { return sceneManager; }
  17. }
  18.  
  19. public Program()
  20. {
  21. Application.EnableVisualStyles();
  22. Application.SetCompatibleTextRenderingDefault(false);
  23.  
  24. sceneManager = new SceneManager();
  25. SceneManager.addScene(new Home());
  26. SceneManager.selectScene("Home");
  27.  
  28. Application.Run(sceneManager);
  29. }
  30.  
  31.  
  32. /// <summary>
  33. /// The main entry point for the application.
  34. /// </summary>
  35. [STAThread]
  36. static void Main()
  37. {
  38. new Program();
  39. }
  40. }
  41. }
  42.  
  43. //SceneManager
  44. using System;
  45. using System.Collections;
  46. using System.Linq;
  47. using System.Text;
  48. using System.Windows.Forms;
  49. using System.Collections.Generic;
  50.  
  51. namespace BPM_C_Sharp_Touchscreen
  52. {
  53. public class SceneManager : ApplicationContext
  54. {
  55. private List<Form> forms = new List<Form>();
  56. protected bool exitAppOnClose;
  57.  
  58. public void selectScene(string scene)
  59. {
  60. foreach (Form f in forms)
  61. {
  62. if ((f.Name).Equals(scene))
  63. {
  64. if (MainForm != null)
  65. MainForm.Hide();
  66. MainForm = f;
  67. MainForm.Show();
  68. }
  69. }
  70. }
  71.  
  72. public void addScene(Form toAdd)
  73. {
  74. forms.Add(toAdd);
  75. }
  76.  
  77. public void removeScene(Form toRemove)
  78. {
  79. forms.Remove(toRemove);
  80. }
  81.  
  82. // when a form is closed, don't exit the application if this is a swap
  83. protected override void OnMainFormClosed(object sender, EventArgs e)
  84. {
  85. if (exitAppOnClose)
  86. {
  87. base.OnMainFormClosed(sender, e);
  88. }
  89. }
  90.  
  91. //Getters and setters
  92. public List<Form> Forms
  93. {
  94. get
  95. {
  96. return forms;
  97. }
  98. set
  99. {
  100. forms = value;
  101. }
  102. }
  103. }
  104. }
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC