943,968 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 1240
  • C# RSS
Nov 4th, 2009
0

C# Multi-form pre-render?

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dekken is offline Offline
2 posts
since Nov 2009
Nov 4th, 2009
0
Re: C# Multi-form pre-render?
Hi Dekken, welcome here!
perhaps you could use the DoubleBuffered property of the form by setting it to true.
Reputation Points: 2035
Solved Threads: 645
Senior Poster
ddanbe is offline Offline
3,740 posts
since Oct 2008
Nov 5th, 2009
0
Re: C# Multi-form pre-render?
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.
Reputation Points: 442
Solved Threads: 89
Master Poster
Diamonddrake is offline Offline
721 posts
since Mar 2008
Nov 6th, 2009
0
Re: C# Multi-form pre-render?
>>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?
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Nov 6th, 2009
0
Re: C# Multi-form pre-render?
Click to Expand / Collapse  Quote originally posted by ddanbe ...
... 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.

Click to Expand / Collapse  Quote originally posted by sknake ...
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.

c# Syntax (Toggle Plain Text)
  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. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dekken is offline Offline
2 posts
since Nov 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Retrieveing binary data out of the database
Next Thread in C# Forum Timeline: Field Initialiser problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC