By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,009 Members | 2,859 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,009 IT Pros & Developers. It's quick & easy.

Application Startup event / Splash+Login Screens

P: n/a
Hi

In my app I have a SplashScreen, a login form and a main form. On launching
the app, I'd like to show the SplashScreen while reading config files and
attempting a database connection. I show progress of these tasks on a label
on the SplashScreen form.
Once this is completed ok, the splash screen should close and the login form
should be displayed. A successful login closes that form and shows the main
form.

I've been trying to get this working using the ApplicationEvents class, but
the problem I'm getting is that the SplashScreen does not close and the login
form appears behind the SplashScreen.

What could be going wrong here? Is this because the SplashScreen does not
get closed automatically until the main form has shown?

I was hoping to get it working this way, but will go back to the old Sub
Main method if not :(

thanks

Richard
Apr 26 '07 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Hi Richard,

Based on my understanding, when you run your application, you'd like to
display a splash screen first and then the login form. A successful login
closes the login form is closed and shows the main form. If I'm off base,
please feel free to let me know.

It seems that you're using VB.NET. In VB.NET, we could enable application
framework and sepecify a splash screen form.

When the application is run, the Startup event handler of application(if
any) is executed first and immediately the splash screen form is shown, not
waiting for the Startup event handler finishes the execution.

After the application's Startup event handler finishes the execution, the
startup form is created and the Load event handler of the startup form is
called(if any). Note that the splash screen form won't be closed until the
Load event handler of the startup form finishes the execution.

If you set the main form as the startup form and show the login form when
the main form is loaded, it makes sense that the splash screen form is not
closed while the login form is opend.

I suggest that you close the splash screen form before you show the login
form in the main form's Load event handler. The following is a sample.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' welcome is the name of the splash screen form
CType(My.Application.SplashScreen, welcome).CloseForm()
Dim frm As New logon
If (frm.ShowDialog() = Windows.Forms.DialogResult.Cancel) Then
Application.Exit()
End If
End Sub

Public Class welcome

Delegate Sub DelegateToCloseForm()

' if the welcome form is closed by the main form, it is cross-thread
operation. so we need to use the Invoke method to deal with it.
Public Sub CloseForm()
If (Me.InvokeRequired) Then
Me.Invoke(New DelegateToCloseForm(AddressOf CloseForm))
Else
Me.Close()
End If
End Sub
End Class

Hope this helps.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 26 '07 #2

P: n/a
On Apr 26, 12:24 am, Richard Bysouth <s...@nospam.nospamwrote:
Hi

In my app I have a SplashScreen, a login form and a main form. On launching
the app, I'd like to show the SplashScreen while reading config files and
attempting a database connection. I show progress of these tasks on a label
on the SplashScreen form.
Once this is completed ok, the splash screen should close and the login form
should be displayed. A successful login closes that form and shows the main
form.

I've been trying to get this working using the ApplicationEvents class, but
the problem I'm getting is that the SplashScreen does not close and the login
form appears behind the SplashScreen.

What could be going wrong here? Is this because the SplashScreen does not
get closed automatically until the main form has shown?

I was hoping to get it working this way, but will go back to the old Sub
Main method if not :(

thanks

Richard
I was hoping to get it working this way, but will go back to the old Sub
Main method if not :(
I gave up a long time ago trying to get the startup to work the way I
wanted it to using the "built-in" methods. I ended up using sub main
and launching my Splash in a seperate thread, loading my main form
into memory, registering my user with the database (most of my apps
use windows authentication instead of a login), sending a message to
the Splash screen's thread to close, and finally showing the main
form. It works exactly how I wanted it too, and after writing it the
first time, I can implement it in other projects without much hassle.

Just my two cents.

Thanks,

Seth Rowe

Apr 26 '07 #3

P: n/a
Hi Linda

Thanks for your answer - that pretty much solves the problem for me. It was
just the call to the Close method of the splash screen that I was missing -
had tried this but had come across threading issues.

The only problem that remains is that for some reason the login form appears
behind other applications i.e. does not come to the front. For example, if I
launch my exe from Windows Explorer, the splash screen shows fine, the login
form appears in the taskbar, but the form itself is behind the Explorer
window. Similarly, after a successful login, my main form appears behind
Explorer!

I did read something on this issue somewhere else but can't find it again -
is there something obvious I might be doing wrong?

I didn't get this issue before I introduced the splash screen into my app.

thanks for your help

Richard
Apr 26 '07 #4

P: n/a
Hi Richard,

Thank you for your feedback.

I peformed a test and did see that the login form is displayed behind other
windows. But after a successful login the main form appears on the top of
all other windows.

I think this may be related to the application framework that the VB.NET
application enables. I set the TopMost property of the login form to true
and the problem doesn't exist.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
CType(My.Application.SplashScreen, welcome).CloseForm()
Dim frm As New logon\
' Set the TopMost property of the login form to true
frm.TopMost = True

If (frm.ShowDialog(Me) = Windows.Forms.DialogResult.Cancel) Then
Application.Exit()
End If
End Sub

Hope this helps.

Sincerely,
Linda Liu
Microsoft Online Community Support

Apr 27 '07 #5

P: n/a
Linda

thanks for your help - that fixes the problem.
Apr 29 '07 #6

P: n/a
Hi Linda

Just discovered a further problem with this. Although the login form appears
to have focus (cursor is in the user id textbox, title bar is active), it
does not actually HAVE the focus! I have to actually click on the form to
activate it.
I have tried many different methods to resolve this but am having no luck.
Have tried:
Me.Focus in the Load/Shown/Activated events
Setting the login form's owner
removing the topmost property.

The strange thing is that if I check the form's Focussed property, this
returns true, even though it does not actually have input focus!

Any ideas?

thanks

Richard
Jun 5 '07 #7

P: n/a
Hi Richard,

I performed a test according to your description, but didn't reproduce the
problem. The logon form gets focused indeed when it appears in my test.

If you don't show the splash screen in your application, i.e. set the
'Splash screen' property to None in the Application tab within the
Properties Designer, does this problem still exist?

If the problem still exists, could you send me a simple project that could
just reproduce the problem? To get my actual email address, remove 'online'
from my displayed email address.

Sincerely,
Linda Liu
Microsoft Online Community Support

Jun 6 '07 #8

P: n/a
Hi Linda

Further to my email reply I think I've solved the problem. I resorted to the
old SendKeys method (something I haven't used since VB6!). I added the
following code to my login form:

Private Sub frmLogin_Shown(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Shown

m_FormLoaded = True
txtUserID.Text = String.Empty

End Sub

Private Sub txtUserID_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles txtUserID.GotFocus

'This hack ensures that the user id field receives focus.
'For some reason it appeared to have focus however was not
responding until
'user clicked on the Form!
If m_FormLoaded = False Then
System.Windows.Forms.SendKeys.Send(ControlChars.Ba ck)
txtUserID.Text = String.Empty
End If

End Sub

private m_FormLoaded as boolean

Bit of a hack, but it works!

Richard
Jun 10 '07 #9

P: n/a
Hi Richard,

Thank you for your sample project.

I run it on my machine and did see the problem. I was running my test
application with VS debugger (press F5 to run the application), and the
login form gets focused. However, if I run my test application by
double-clicking it, I see the same problem in my test application.

When I run the application by double-clicking it in Windows Explorer, I
notice that the focus is taken from the Windows Explorer to the splash form
when it is shown. When the splash form is closed from within the
application, the focus is returned back to the Windows Explorer.

I think this problem is caused by the internal implementation of splash
screen.

I have tried your workaround, but unfortunately it doesn't work on my side.

I think a simple workaround of this problem is to cancel the splash screen.
Instead, we could show the splash form as a normal form manually. To do
this, add a module in the application and declare a public splash form in
it. Show the splash form in the application's Startup event handler and
close it in the main form's Load event handler.

Hope this helps.

Sincerely,
Linda Liu
Microsoft Online Community Support

Jun 11 '07 #10

P: n/a
Hi Linda

Thanks for your suggestion. All is working ok at the moment with my
workaround, however I'll certainly bear your solution in mind if I get any
further problems!

Richard
Jun 12 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.