Bring to the front

Harcon

Member
Joined
May 8, 2012
Messages
18
Programming Experience
1-3
I'm loading a form Frmmain and when it is loaded, i load the loginform.
But when i do that, the loginform goes to the back. and i can't get in front, so the user knows he has to logon first.
Before he can really use the application.
 
If it doesn't work then, almost certainly, you're doing it wrong. As you haven't shown us what you're doing, there's really no way that we can know what's wrong with it.
 
If it doesn't work then, almost certainly, you're doing it wrong. As you haven't shown us what you're doing, there's really no way that we can know what's wrong with it.

this is what i use in the loginform
VB.NET:
    Private Sub LoginForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.BringToFront()
        frmMain.SendToBack()
        Me.UsernameTextBox.Focus()

    End Sub
 
None of that code should be required at all. If I had to guess (which I do, because you haven't shown your code) I would say that you're probably displaying the login form from the Load event handler of the startup form but not as a modal dialogue.

There's really only two reasonable ways that I can think of to show a login dialogue at application startup. The first option would be from the Startup event handler of the application. You would call ShowDialog on the login form and, if the user fails to login successfully, you cancel the application and the startup form is never even created, never mind displayed. The second option would be from the Shown event handler of the startup form. You would call ShowDialog and the login form would be displayed over the startup form, which must have already been displayed. If the user fails to login successfully then you can immediately close the startup form or provide access only to functionality that doesn't require authentication.
 
Back
Top