C# Loading and hiding page - c#

I have a C# project with two forms: a loading form and a login form. The loading form has a circular progress bar and a timer that updates the progress bar until it's finished loading. When the loading form finishes loading, it's supposed to hide and the login form appears. However, I'm experiencing an issue where the loading form changes position slightly before hiding, and I'm not sure why this is happening.
I've tried some basic troubleshooting steps, such as checking the form's Anchor and Dock properties, but the issue still persists. Has anyone else experienced a similar issue when using a timer and circular progress bar and have any suggestions on how to fix it?

One thing I would recommend, for any project in general is not opening/closing so many forms but rather loading new forms inside a panel that is on one main form.
This would maybe help with the jittering/glitching that you are experiencing and in general will improve the overall appearance of your application.
To add a form to a panel:
Form someForm = new Form();
someForm.TopLevel = false;
myPanel.Add(someForm);
someForm.Show();
Note that you must set the child form's top level property to false. This method of handling forms overall will reduce the opening/closing animations of your project and any graphics glitching.

Related

How to block mouse click events from another form

I have a winforms single form application that uses a "Thickbox" I've created whenever the loads a new view into the application form.
The "Thickbox" shows another form in front of the application's form that is semi-transparent and has a user control that is the box itself.
This thickbox can be shown a modal dialog and in that case I have no problems at all, but it can also be shown as a non modal, for instance, when the user switches views in the main form, it shows thickbox with a loading animated icon.
The problem is that when the thickbox is shown as non modal, it doesn't block the user from clicking on the buttons of main form of the application.
When thickbox is shown nothing happens, but as soon as it's closed, the click is being processed by the click event handler of the relevant button in the main form.
I can't use ShowDialog since I can't block the UI thread, and I need to get the indication from the main form when to close the thickbox,
I can't set the Enabled property of the owner form as described in this answer (though I've tried various versions of this solution, nothing helps)
I've tried using the win API function BlockInput as descried in this answer, but that didn't block the input,
I think my best chance is using the Application.FilterMessage method, but I couldn't get that to block the mouse clicks as well.
It would be great if I could encapsulate the mouse click blocking inside the thickbox form itself, so that it would be usable easily with other applications as well, but
a solution on to the calling form would also be very much appreciated.
I'm glad to announce that the problem is finally solved.
After spending a few days attempting to recreate this bug in a new application, re-constructing the main form in the application, comment out parts of the code in the main application, and generally just shooting all over to try and find a lead, It finally hit me.
The application behaved as if the clicks on the thickbox was queued somehow and only activated when the thickbox was closed. This morning, after fixing some other bugs, The penny finally dropped - all I was missing was a single line of code right before closing the thickbox's form:
Application.DoEvents();
The annoying thing is that it's not something that's new to me, I've used it many times before including in the main application and in the thickbox code itself... I guess I just had to let if go for a while to enable my mind to understand what was so painfully obvious in hindsight...

Load controls with progressbar before Main Forms appear

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.

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.

C# Main form refresh with dynamic controls

I'm developing a windows form application with controls on the main form that retreive their values from a mySQL database. When the database gets updated I need the form to repaint and refresh the controls. Can anyone reccommend a solution to this? On sub forms I've instantiated a new instance of the form and dispose of the old one, but I can't do that with the main form. Thank-You for considering my question.
I'm not sure if correctly understood your question, but you could put your controls inside of a user control and use-it in the main form. Then, you could do the same you did with the forms: dispose and create a new one.
This should solve your problem, however, you may have some problems with scrollbars and the resizing of your form.
If it were me, I wouldn't dispose of a UI with another, that is in focus for the user. That would kind of irritate the user especially if the update is automatic.
Suppose you have view-only controls like gridview or labels updating with live values, then you can put a time interval and display a seconds ticker clearly telling the user when an update is going to happen.
You should consider having an update method on all your controls (or one usercontrol having all the controls) which you can trigger to update the controls at timed intervals.

Form is not laid out correctly

I have a WinForms form hosted in VB6 application (I am not sure if this is significant). Sometimes form controls are layouted incorrectly (primarily Anchor property doesn't work). If I just resize a form by mouse - the form is drawn as it should. Is there any method that may solve my layout problems without manual form resizing? I tried PerformLayout, Invalidate and Refresh methods... but they don't solve my problem.
You could handle the form's Layout event to layout the controls the way they should be.

Categories

Resources