In my application it takes some time to loan my initial screen(1-2 mins). Since it has so many controls to be filled by Database.
So I need to have a splash screen, it will load(probably with a progress bar) and stays while main form loads. Means in background I need to load main form (better with out showing)
Only main window finishes loading, it notifies to splash, the splash will go off and main will be visible.
I tried to achieve above with several way but no success.
Any one can help me ?
look at this Splash screen
and this Splash screen class
FormSplash splash = new FormSplash();
this.BeginInvoke(
new MethodInvoker(
() =>
{
splash.Show();
}
)
);
// main form code here
// at end of loading code
splash.Close();
The above code belongs in Form_Load of the main form.
There are a couple of good approaches discussed at Show a splash screen at once (in fact to me this and the other question appear to be duplicates).
The best way and using the API is
SplashScreen splash = new SplashScreen("splashscreen.jpg");
splash.Show(false);
splash.Close(TimeSpan.FromMilliseconds(2));
InitializeComponent();
Related
I am using Devexpress winform for my project. There are three forms simply. The first is MainForm that used MdiParent, the second is FormArticles that used listing articles about law into GridControl. And the last is FormArticleView that used viewing selected article into pdfViewer control. I managed to use documentManager and SplashScreenManager while loading Mdi Child forms and articles into one of Mdi Child form FormArticles. Here is my code:
public prjLibrary()
{
InitializeComponent();
var frm = new FormArticles{ MdiParent = this, Dock = DockStyle.Fill };
frm.Show();
}
While transition one form to another, the forms is fractured and after load it is fixed. Here is my screenshot:
And here is fixed view:
How can I fix fractured view while transition of forms?
This is because when the form from the first screenshot is getting focused, the controls have to be rendered in their Paint-event. This seems to take some time but you can see the fractured text is shown in rectangles where I think the underlying controls (radio buttons, text boxes, labels) are placed. So they are not rendered yet and not ready to go while any other call is blocking the thread. I think the problem is that you create a new form in your mainForm's constructor.
Anyway, it is a good practice to perform heavy tasks (which seem to block the painting of your controls) in a background thread having the UI waiting for the response. If this is too hard to do, try to do it after the UI is shown to the user. This could be the OnLoad- or even OnShown-event.
Note that I don't want to encourage you to write any business code into the UI layer but that seems not to be the question here.
I'm trying to implement some complement views inside my application and I would like to have a better layout control over them. I don't know how to explain in words what my desired functionality is, so I made it through with some photoshop help, hoping you could give me a hand to implement it.
My application now looks like this:
(i need reputation to post images so.. sorry for the links)
http://i59.tinypic.com/2ikv8m1.jpg
When I minimize the modeless form which is focused in the previous image, I would like to be able to see it (and handle it to maximize or close) inside my main form as I show in the image below (made it in photoshop)
http://i58.tinypic.com/1e28go.jpg
Hope someone can lead my into a solution and thanks for the support.
EDIT: I need to be able to move that form outside my main form, even to a different monitor.
If you don't want to use the MDI approach, then set TopLevel of the modeless Form to false and add it to the main Forms Controls collection before showing it:
Form frm = new Form();
frm.TopLevel = false;
this.Controls.Add(frm);
frm.Show();
*Obviously changing Form to the correct type of your modeless form.
If i understand what you are trying to do, you want to minimize a certain form but still see it within your app (im assuming like Excel or Word)
You can do something similar to what Idle_Mind said, but enclose both in a Form instead of the parent.
Form fParent = new Form();
fParent.Dock = DockMode.Fill;//i think this is the syntax. Use this if you want the form to fill to the screen
Form fChild = new Form();
fChild.TopLevel = false;
fParent.Controls.Add(fChild);
fChild.Show();
Here, it should minimize to the lower left part of the parent form. You can then size the parent to whatever you want it to be.
I have a form that i want to always be on top whenever it is opened in the application but i dont want it to be on top when the main form is minimized or another application is navigated. I want it to be on top only in my application.
Following the answer in the question : How to make a window always stay on top in .Net?
this.TopMost = true;
Makes the form on top but the form is still on top when another application is navigated to or the main form is closed.
Pls how do i make the form only on top in the application while enabling user to still work on the main form?
You are looking for an owned window. It is always on top of the owner and it gets minimized along with the owner. Good examples of owned windows are the various helper windows inside Visual Studio. You can undock them but they'll always stay on top of the VS main window.
You create an owned window by displaying it with the Show(owner) overload. Or by explicitly assigning its Owner property.
Set the top level and then set the owner, example below.
public Form1()
{
InitializeComponent();
Form2 f2 = new Form2();
//top level not really needed
f2.TopLevel = true;
f2.Show(this);
}
I have a C# application which runs into trouble when it comes to multi-threads / backgroundworkers when I'm using a splash screen before I load the main window.
my code look something like this:
[STAThread]
private static void Main()
{
.. do some stuff
ShowSplash(); // where i show a splash screen and load some stuff
...
As the last step of ShowSplash, I do the following:
new MyCabApplication<MyMainWorkItem, MDIParentForm>().Run(); -- where i load the form through cab.
The problem is that when I do that I get the following exception:
Starting a second message loop on a single thread is not a valid operation. Use Form.ShowDialog instead
Any idea what can I do?
Here is my showsplash function:
private static DialogResult ShowSplash(AutoResetEvent controller)
{
// create and register splash screen
splashScreen = new PointSplashScreen();
Application.Run(splashScreen);
return DialogResult.OK;
}
Two solutions:
Instead of using Application.Run, just create a new instance of the form and then call ShowDialog. Move new MyCabApplication<MyMainWorkItem, MDIParentForm>().Run(); outside of the Splash Screen after the call to ShowDialog(). You can check properties of the Splash screen if this code should not always be run.
Instead of using Application.Run(Form), use Application.Run(ApplicationContext). You will need to create a new ApplicationContext and move your code there.
Solution 1 is easier.
It sounds like MyCabApplication extends Application. The Run method starts a WinForm application by starting a message loop that handles window messages.
Because you are already showing UI, there is already a message loop running, so you cannot start another. To get your main form to show up, make a new instance of it and call Show():
var form = new MainForm();
form.Show();
I am showing a splash form by starting a new thread immediately before running my main form.
In the method that is run by this thread, I am using Application.Run as shown in Option 1 below. Is this a correct way of doing this, or are there problems waiting for me becaue I have called Application.Run twice? An alternative is Option 2, also shown below where I call .ShowDialog() to display the form.
The splash form itself closes after a specified time, controlled within the form itself, and both options appear to work well.
So my question is: Which is preferred - Option 1 or Option 2? If you could give specific reasons for one or the other that would be great.
Thanks.
Snippet of Main:
// Run splash screen thread.
Thread splash = new Thread(new ThreadStart(ShowSplash));
splash.Start();
// Run main application.
Application.Run(new MainForm());
Show splash form option 1:
static void ShowSplash()
{
Application.Run(new SplashForm());
}
Show splash form option 2:
static void ShowSplash()
{
using (SplashForm splash = new SplashForm())
{
splash.ShowDialog();
}
}
Option 2 will probably run into trouble because then you are using the same Mesageloop as the MainForm but from another thread.
Option 1 is fine.
I realize that this may be an unusual viewpoint but have you considered not using a Splash screen and instead showing the information on the 'welcome page' or 'help > about' screen instead?
There are a handful of reasons to do this:
Unless you get into multi-threading, a Splash Screen may not repaint properly if some alert/msgbox pops up over the top of it, negating the benefit of the splash screen entirely.
Splash screens that show 'you have plugins x, y and z' installed can't really tell this until that information has been loaded up. By the time this info is loaded, your app is ready to go, so you'll either close the splash screen or it'll be in the way of the user.
If I look away and miss the splash screen, I'll miss whatever information you're telling me. If 'License expires in 3 days' is part of that information, and today is Friday, that means I won't realise that on Monday, I can't use the app. Obscure, but I've seen it.