Load controls with progressbar before Main Forms appear - c#

I have a MDI form on which I have a menu, Sidebar and somewhat around 50 More controls which makes my application interface very heavy. Also I am loading something around 500 user data which is also loading on my MDI form List box.
However all these process takes a lot of time to load, what I want to do is to load all the stuff just before displaying my MDI form.
Lets say, when I click on login, It should show a progress bar and when progress bar loads to end with all the configuration like "User List Display, Loading of controls and other settings": Then only MDI form should appear.
I have also gone through the DevExpress control:
Splash Screen: http://documentation.devexpress.com/#WindowsForms/CustomDocument10826
Splash Screen video: http://www.youtube.com/watch?v=mFl6P9I6c5A
But this is proprietary.
Is there any control available with winforms so that I can accomplish it.
Like the way we use to see with Visual Studio, Photoshop and other softwares which are very heavily build.
Also, what would be the ideal way of doing this. I have read a lot about, backgroundWorker and Threading. Just need advice on what would be the best way as per you guys. And yes, the smartest way.

Related

How do I know that a MDI child form has visually changed?

I have MDI WinForms application written in C#. Normally only one MDI child form is visible and all others are in background. Child forms content may occasionally change in background (for example, web browser control may be displaying a page that is dynamically changing every N seconds, chart controls are being filled with data as time goes on).
I want to show small previews of child forms when user hovers a mouse over or clicks on a special button in a toolbar of the main form. I can successfully use PrintWindow function as described here to make screenshots of child MDI forms. This works even for non-active child forms. The only problem is that taking every screenshot may take significant time (about 100-120 ms), probably because of the complex structure of the forms, so that if I make screenshots right before I want to show the previews then this creates a noticeable delay, especially when there are a lot of child forms (e.g. 10-15).
I want to optimize this and re-create screenshots only when it is really needed. Here is what I mean. Initially would I create screenshots for all the forms, store them in a "cache" and show previews. Later, when I need to create previews again, I would like to determine somehow that visual content of MDI form has changed (or change is pending) and re-create the screenshot only in that case, and otherwise use "cached" screenshot.
I tried to implement this by overriding of WndProc function of the child form class and looking for some messages like WM_PAINT or WM_SETREDRAW. But when I log all messages I see neither WM_PAINT nor WM_SETREDRAW even while the form is active (in foreground) and the web browser control on it constantly updates its page. Probably those event are sent directly to the controls of the form, but not to the form itself.
I don't want to traverse every form and connect to "changed" events of all the controls, because all of them are very different and not all have such notification events.
I guess that every control when it wants to change its visual representation sends some notification to OS to force self repaint. So, is there any way to detect such notification from any control inside MDI child form?
UPDATE:
I found WinAPI GetUpdateRect function that should return a rectangle that needs to be redrawn. I thought that if it returned non-empty rectangle then that would mean the screenshot needs to be updated. I tried to call it before the call to PrintWindow, but it always returns empty rectangle.

how to re-use my windows forms in a dashboard that works like HTML frames?

My C# standard windows forms app is finished, it has 10 forms. But the new requirement is now to change the "multiple forms" to one dashboard where you click a link on a bar on the side or top and switch between forms in the main area of the dashboard one at a time, pretty much exactly the same way an old HTML frame works with framesets (just imagine my Windows Forms are framesets).
Without going into much detail, each of these forms are pretty involved, multiple threads and so on, and I am looking for a simple trick to display them, as oposed to recoding the entire thing.
I looked at http://www.codeproject.com/Articles/37397/A-Multipanel-Control-in-C
but it's not what I want.
Is there a way to do this?
If you convert the forms into custom controls, it then becomes pretty simple to use the TabControl http://msdn.microsoft.com/en-us/library/system.windows.forms.tabcontrol.aspx to display the custom controls on the surfaces of the Tabs it contains.
By making them custom controls you avoid the mixing of the code for each of them (they remain distinct) but they also become easily added to other surfaces. I do this with a UI with a dozen display tabs.
I would recommend that you either use a tabbed control, or use an MDI Container, or a combination of both. The MDI has some nice behaviors that you'll get for free by implementing it. You could hard code each tab to each form, or have a dropdown that selects each view. If you want to manage the lifecycle of each form, you could implement a singleton pattern on each, or use IOC.
Not entirely sure this is going to solve your problem, but if you have questions or more details, let me know.
I resolved this using MDI as suggested above, works great in .NET Windows Forms 4.0 and 4.5.1.
In the parent form:
Declare a new child form.
myNewChildForm.MdiParent = this;
set child form StartPosition to Manual.
set child form Location to 0,0.
set child form WindowState to Maximized.
set child form Dock to Dockstyle.Fill
That does the trick.
Thank you all.

c#.net splash screen loading

I'm developing a C#.NET (4.0) WinForms application. On startup I want to have a splash screen that fills a series of datagridviews on a different form.
At the moment the main form loads that data into the DataGridViews on Form_Load but this makes the Form hang there while this is happening.
So how do I call the method that loads the values to the DataGridView from the splash screen?
I'm rather new to C#.NET, I'm trying to move away from VB.
I would have the splash screen launch the real form where the DataGridViews are, and in that form put the data loading method on its own thread. For a nice and simple and beginner way, use a BackgroundWorker. For more advanced control use Threading.
How to use background worker.
Threading Class Docs
Very good tutorial on threading
EDIT:
As you mentioned in your comment it sounds like you still don't want the form to even appear until its done loading in the data. The easy way to do this is have the main form be hidden from startup, and in the on-load event launch the splash screen, and then when the method that does the data loading returns, set the visibility to true and close the splash screen form.
There are many ways to have a form start hidden. Here is a good forum question with lot of answers on different ways to do it.

How to improve the loading time of winform?

I have a WinForms application. the main form is has a lot of controls and that is one of the reasons that makes it load very slow. what I would like to do is to make the form load faster.
I have set the beginupdate and endupdate. The form is not being rendered in the background worker thread, because this is the main form. There are no initial forms. When the user clicks the application icon, this is the first form that loads up. Adding a progress bar or any splash form is not a good idea for me.
I have checked other questions here on Stack overflow but they do not seem to face the same problem as I do.
If there are some examples/ideas you have in mind, it would be nice of you if you can share it with me.
A few suggestions:
Try to minimise the complexity of your UI. Your users will thank you and you'll have fewer controls to load. For example, if you have 3 or 4 controls that are not used often, can you move them into a dialog or fold-out "advanced" section of your form, so you can defer creating/showing them? Are all the controls needed? Really? Think about the workflow you are trying to achieve - is the current set of controls the simplest way to achieve the workflow? DO all the controls need to be shown at once? Perhaps you could place them on to separate tabs in a tab control (and thus only actuallyl create the controls as the tab is shown)?
Can you reduce the range of control types used? Each new type of control may cause your program to load up a new dll to support it. Every dll that has to be initialised causes extra startup time.
Are you using any controls that are slow to start up? A simple text field will be fast, but a complex graphing control may be slow.
How many assemblies (of your own) are loaded? Combine all the code into a single assembly (e.g. with ILMerge) and load times will probably improve quite a bit.
Remove any initialisation code that isn't needed. Can you simplify the initialisation? Can any initialisation be deferred (e.g. only create some member variables when the user clicks on the first button that actually needs that data to be present, Don't try to create a connection to a database if it's not actually needed yet, etc)
Can you defer creation of (some of) the UI? For example, you may be able to place a group of controls into a separate UserControl form, and then add this form programmatically to your MainForm shortly after startup (e.g. on a Timer). This will allow your MainForm to appear very quickly, and then be "populated" shortly after with additional controls, which may not improve the actual startup time, but it will "feel" a lot faster and more responsive to start up. (This approach can also be extremely effective if your MainForm scrolls and those extra controls are initially not on-screen, as they only need to be created if the user scrolls down enough to see them)
Are you displaying any information that might be slow to load (e.g. large bitmap images or data fetched from an SQL server)? Can you defer the loading of them or run it as a background thread? Use compression to speed up loading? Reduce their resolution to minimise the amount of data that must be loaded? Pre-process data and store it in a quick-start cache for the next time the program is run?
Can some controls be replaced by an optimised approach? e.g. You can create a "button bar" as a set of 10 separate controls, or as a single control that draws iself with the appearance of 10 buttons. It's much easier to make the single control initialise and redraw faster than 10 separate controls.
And of course, once the most obvious low-hanging fruit has been collected (or even before):
Run the program under a profiler and see where it's spending its time.
Try to minimize the code that executes during on load of main form or any of the control that is placed on the main form.
You can also explore NGEN which is Microsoft's tool which helps in improving managed app's performance
When a form loads it initializes all its controls.
The Form itself isn't taking you a long time.. It's your controls.
Go over your controls and check what can be improved in their constructors and initializers.
Do you need all of the controls immediately? If not perhaps you could load them programmatically after some event fires that lets you know you need that control.
If you have several controls to a parent control, call the SuspendLayout method before initializing the controls to be added.
After adding the controls to the parent control, call the ResumeLayout method. This will increase the performance of applications with many controls.
For example:
private void LoadData()
{
// Suspend the form layout and load the data
this.SuspendLayout();
LoadMyData(); // logic to load your data will be here
this.ResumeLayout();
}
EXPLANATION:
SuspendLayout() - Stops the layout object from being updated and thus the component does not spend any time making calculations for repainting until the layout is resumed.
ResumeLayout() - Recomputes the layout once after all of your changes are made, resulting improvement in performance.
Why use SuspendLayout() and ResumeLayout()
It prevents layout accidents when controls have layout properties that affect each other.
It adjusts multiple layout-related properties like Dock, Auto-Size etc.

What's the best way to "dim" background of winform while displaying a dialog?

I'd like to implement a feature in my application where show a dialog to the user, and the main form (similar to how jQuery looks). My only idea is to take a screenshot of the form, place it as the background of a panel (with opacity to my liking) then pushing the panel over everything on the form. I have to believe there is a better way of doing this, any suggestions?
The Opacity property is what you need to "dim" a form. You'll need to create an overlay, my code in this thread shows how to do this.
Be careful to not make it look like your program is displaying a UAC prompt. While perhaps appropriate in browsers, the user will never have any trouble recognizing that a window overlaid by a dialog is disabled. Controls paint themselves differently to make it clear.
Why not just set the opacity to something like 50% of the parent window just before launching the modal dialog and then back to 100% when the modal dialog is dismissed? This isn't exactly what you're asking for serves the same function for the end user.
If you do want to do something like your JQuery example you would indeed have to do the screen cap/augment/set as background idea that you described.
I know this is an old thread but if still interested you can take a look at this project.
Download Project

Categories

Resources