How to display Welcome Screen in Winform? - c#

I am doing win form project.(C#). In that project i am willing to add welcome screen. So i created a welcome screen. But, It want to show a few minitute and automatically closed and open login screen.
System.Threading.Thread.Sleep(1500);
LogIn n = new LogIn();
n.Show();
I try this code in form shown,load, activate events. BUt no use. Any one know what to do?.

Here's a tutorial explaining how to make a splash screen.

Add a line for splash screen in Program.cs. Run a timer in splash screen and close the form.
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FSplash()); // This is your splash form << added
Application.Run(new FMain());
}

In my opinion, you cannot create a splash screen in .NET for a .NET application:
The purpose of a splash screen is to distract users from long waiting times, until the application has been loaded, started and initialized.
Since a .NET application itself already has some startup time, there is no splash screen available within this time.
My solution
So in my applications, I am doing it the following way:
Write a small, tiny native C++ application.
Display a topmost bitmap (window with no borders) when the C++ application starts.
Let the C++ application start the actual .NET application.
The .NET application starts and when it is finished starting and initializing, it tells the C++ application to close. This is done through IPC.
The inter-process communication is done the following way:
The C++ application writes a temporary file.
When calling the .NET application, the file name is passed as a command line parameter.
The C++ application polls regularly whether the file exists.
The .NET application deletes the file as soon as the splash screen has to be hidden.
The C++ application exists as soon as the temporary file does not exists anymore (or a timeout occurs).
I know this is not 100% perfect, it was the most suitable solution I came up since I started developing .NET applications, years ago.

Related

How to create a console application that runs in background?

I created app that open every time that I start pc. So its so annoying to close it every time so I'm wondering if its some code that will hide my console app. I saw videos and tutorials on forms but idk how to do it with console app.
The easiest way to do this is change your console app to a windows app.
Console apps get a console made for them by Windows. But if you change it to a windows forms app, then windows expect the application to make a window, so if you never make a window, then it will never show
The other way is to turn your application into a service. This has some additional requirements in terms of programming
Option 1
You can use this run command:
start /min "SomeTitle" MyConsoleApp.exe myarg1 myarg2
Thus it will be on the taskbar minimized.
Option 2
If you use a file link in the start menu, select the start minimized option for the exe.
Option 3
Using a WinForm app you will be able to use a tray icon by setting the main form as not visible, to say it simply because it can be complex according to the expected behavior, and it will not be in the taskbar too.
Option 4
If you don't want a main form, create a win form app, delete the form file and the code in the main method, and you're done, without GUI nor console, no main input and no main output but you can show MessageBox and some forms when necessary, just a background process only visible in the Task Manager.
With that you can add a tray icon to to offer exit and some status information for example.
Option 5
Also you can create a windows service:
.NET console application as Windows service
Note
In all cases, if you don't use an internal message events dispatcher like the WinForms Application pattern or WPF and so on, be carefull to not saturate the CPU with the processings like with loops and use Thread.Sleep() between iterations or any thread idleing pattern or some timer if necessary.

Display image before form launch - Compact Framework

I have a Windows Mobile application where in the Main method I show the Main form:
[MTAThread]
static void Main()
{
new MainForm().ShowDialog();
}
When the program starts I see the the typical animation loading:
Instead of this animation I want to see an image (full screen), how can I do?
There you can find a complete sample on how to embedd a splash screen to your .NETCF application.
.NET Compact Framework Sample: Splash Screen
Don't be confused that link points to the .exe, this sample is made as an installer but as the end result you'll see the code itself.
One unfortunate thing about the CF SLR is that it shows that wait cursor down in the bowels when it starts JITting and loading classes. There's no way to get rid of it. You can create your own splash screen, but keep in mind that it won't show until the framework is loaded enough to display it unless it's a separate app. Even with a separate splash screen, that wait cursor will still be there, so it's not an "instead" like you want, but an "also".

Launch a custom screensaver + lock machine

In my application I'd like to accomplish 2 things when a user wants to take a break and clicks a log out button.
Lock the machine
Launch a custom screen saver that would show the time the user is logged out.
I managed to do the lock easily by:
[DllImport("user32.dll")]
private static extern void LockWorkStation();
I found a tutorial on how to make a custom screen saver. I downloaded the sample code and it worked fine. But when I added the LockWorkStation(); line it killed the screen saver.
Can you help me with this or suggest a workaround?
EDIT
This screen saver from tutorial is just w WinForm. Should I somehow install it to the system? Is it possible form my application level?
The solution most likely is the following:
Lock the workstation
Show the screensaver
For the second step, the following is important:
You application is simply a program showing a window. As such any windows it tries to show are not shown to the user when the workstation is locked.
Your window will only be shown when you register your program as a real screensaver, set it as the current screensaver and than start it, for example using the SC_SCREENSAVE message.

Close a windows form without exiting the entire application

Environment
Windows XP SP3 x32
Visual Studio 2005 Standard
Device/Platform: Honeywell Dolphin 9500 with Windows Mobile/Pocket PC 2003
NET Framework 1.1 and .NET Compact Framework Framework 1.0 SP3
Goal
I currently have an application with 3 forms. The first form is something like a splash screen but I have not yet decided whether or not the user will be allowed to reopen it. The second form is an aggregate listing of items that will be displayed, one by one, in the third form.
I would like to be able to open the first form and wait for a button press. When that button is pressed, I would like to open another form and dispose of the first. Once an item is selected out of the list box on the second screen, I would like to display the third form and possibly dispose of the second form. The user also needs to be able to reopen the second form to select another item to be displayed on the third form. That being said, I probably don't want to dispose of the second form. However, memory is an issue on this device (64MB shared between storage and system memory) hence my desire to dispose of things when I can.
Problem
You can probably guess this by the title, but when I close/dispose of my first form, the entire application closes. Now that I have read up on the matter a little, I am aware that this has to do with this line: Application.Run(new Form1()); or whatever my form happens to be named.
Things I Have Tried
this.Dispose() - closes the entire application
this.Close() - closes the entire application
I also saw multiple people recommending one instantiate their form (Form f1 = new MyForm();), show it (.Show();), and then use Application.Run(); with no arguments. When I try this, I get "No overload for method 'Run' takes '0' arguments"
ApplicationContext does not exist in version 1.1 of the .NET Framework
Code
static void Main()
{
Application.Run(new Welcome());
}
private void btnBegin_Click(object sender, EventArgs e)
{
Form wof = new WorkOrderForm();
wof.Show();
wof.BringToFront();
// Here is where I would like to dispose of the Welcome form
}
You can call Application.Run() with your "main" form, this will still allow the application to close properly when the form closes, but hide it (Visible=false) whilst you show the splash screen, or just show the splash screen on top of it.
Create a hidden form that you pass to Application.Run(). When you decide it's time for the app to go down, close that hidden form.
I keep answering my own questions...
I posted this identical issue on the MSDN forums and was told to use the ApplicationContext object instead of a new Form object as a parameter in Application.Run. I am going to try that now. For now I will leave this unanswered.
EDIT: Well, I recant. Application context does not exist in the .NET Framework v1.1
EDIT2: Actually, it seems that it does (http://msdn.microsoft.com/en-us/library/system.windows.forms.applicationcontext(VS.71).aspx), however it does not appear to exist in the Compact Framework version 1.0 SP3.
Is it required to have 3 forms?
One way is to create 3 panels in 1 form and just show the active panel.

WPF form in a console app

Im running a console app that loads a dll and calls a method from that dll that creates a WPF form. So I'm just calling to Program.Execute() method and it does all the creation of the form. All reflection business goes well, but the form does not appear.
I've been told that this is because a console app does not have a windows message loop, but I'm sure there is a way to simulate that. For example, I tried playing with System.Windows.Threading.DispatcherFrame, but to no avail - the form still does not show up.
Did anyone else face this problem?
Just call WPF's Application.Run(). Or Window.ShowDialog(), same thing. You will also have to apply the [STAThread] attribute on your Main() method.

Categories

Resources