Event - After form is displayed for first time
-
Is there an event that runs right after the form is displayed for the first time? I would like to show my form with no data displayed on it, then display a login screen on top of it. After correct login and password populate form with data. Thanks.
There is no event that is fired one-time only right after the form is displayed. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
There is no event that is fired one-time only right after the form is displayed. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Ok, how do I accomplish this: The app starts. The user sees the main form with all of its controls but without any data population. A login form also appears on top of this form. After typing a valid username and password the login form goes away and the main form is populated with data. What I need help with is where in the main form do I call the login form. Thanks
-
Ok, how do I accomplish this: The app starts. The user sees the main form with all of its controls but without any data population. A login form also appears on top of this form. After typing a valid username and password the login form goes away and the main form is populated with data. What I need help with is where in the main form do I call the login form. Thanks
I guess I don't understand exactly what you are trying to accomplish. I have an MDI application that displays the main form before firing the onload event. My login form in in the main forms' "OnLoad" event so it looks like this:
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load frmLogin.StartPosition = FormStartPosition.CenterScreen frmLogin.ShowDialog() End Sub
Then my login screen shows in the middle of the screen and in dialog mode so that it has to be responded to before the user can access the main form. -
I guess I don't understand exactly what you are trying to accomplish. I have an MDI application that displays the main form before firing the onload event. My login form in in the main forms' "OnLoad" event so it looks like this:
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load frmLogin.StartPosition = FormStartPosition.CenterScreen frmLogin.ShowDialog() End Sub
Then my login screen shows in the middle of the screen and in dialog mode so that it has to be responded to before the user can access the main form.Is your main form displaying behind the login form? In your example you call the login form from the load event of the main form. When the main form load event fires the main form is not yet visible on the screen. Your login form is displayed as a dialog and stops the main form from displaying until the login form closes. I would like to have the main form displayed behind my login form. Its kind of like the way Outlook works. You click on the icon, you see the Outlook screen but the login screen is in front of it, preventing you from doing anything until you provide a correct user name and password.
-
Is your main form displaying behind the login form? In your example you call the login form from the load event of the main form. When the main form load event fires the main form is not yet visible on the screen. Your login form is displayed as a dialog and stops the main form from displaying until the login form closes. I would like to have the main form displayed behind my login form. Its kind of like the way Outlook works. You click on the icon, you see the Outlook screen but the login screen is in front of it, preventing you from doing anything until you provide a correct user name and password.
dptalt wrote: Is your main form displaying behind the login form? You can't launch a modal form with ShowDialog from the Load event of another form and expect both forms to show up. You'll see the modal form, but not the form that launched it. This is because the form won't actually show up until it's Load event is completed. Which, in your case, won't happen until the login form closes and control is returned to the line after your ShowDialog call. In Outlook, the login is not controlled by the main form. Rather is being controller by a component that manages the data store Outlook uses. In your application, you can't use ShowDialog to launch a login form. What you probably need to do is create your main form so it creates an object that wraps your datastore. When your controls are put up, they have to check to see if a user is logged in or not. If not, grey out the control or whatever you want. But, when you actually have to get to the data, you call this component and it will put up the modal login form if it needs to, not your main form. If you want to update the status of your controls based on the existance of a valid login or not, you can then do that in the main form's Activated event. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
dptalt wrote: Is your main form displaying behind the login form? You can't launch a modal form with ShowDialog from the Load event of another form and expect both forms to show up. You'll see the modal form, but not the form that launched it. This is because the form won't actually show up until it's Load event is completed. Which, in your case, won't happen until the login form closes and control is returned to the line after your ShowDialog call. In Outlook, the login is not controlled by the main form. Rather is being controller by a component that manages the data store Outlook uses. In your application, you can't use ShowDialog to launch a login form. What you probably need to do is create your main form so it creates an object that wraps your datastore. When your controls are put up, they have to check to see if a user is logged in or not. If not, grey out the control or whatever you want. But, when you actually have to get to the data, you call this component and it will put up the modal login form if it needs to, not your main form. If you want to update the status of your controls based on the existance of a valid login or not, you can then do that in the main form's Activated event. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
It works fine for me. Just set you main form "Window State" to "Maximized" and then you can use the logon.showdialog in the main forms Load event and it will appear in front of the Main form but both will display. Code follows Main Form w/ WindowState property set to "Maximize"
Public Class Form1
Inherits System.Windows.Forms.Form#Region " Windows Form Designer generated code "
Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Private Sub InitializeComponent() ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 266) Me.Name = "Form1" Me.Text = "Main Form!!" Me.WindowState = System.Windows.Forms.FormWindowState.Maximized End Sub
#End Region
Private Sub Form1\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim frm As New Form2 frm.StartPosition = FormStartPosition.CenterScreen frm.ShowDialog() End Sub
End Class
Login Form
Public Class Form2
Inherits System.Windows.Forms.Form#Region " Windows Form Designer generated code "
Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If
-
Ok, how do I accomplish this: The app starts. The user sees the main form with all of its controls but without any data population. A login form also appears on top of this form. After typing a valid username and password the login form goes away and the main form is populated with data. What I need help with is where in the main form do I call the login form. Thanks
sorry for replying in the center if you problem is not solved then there is a solution for you. You have many variables in your application. May be one of them is UserID. you can check that in Activate event of main form ' any variable which you set, when user logs on. ' where is 0 is user has not signed in yet if userID=0 then dim frm as new LogOnForm frm.showDialog ' do some thing if required end if and offcourse once the user is logged on then UserID <>0 so it will never show the logon form again.
-
Is there an event that runs right after the form is displayed for the first time? I would like to show my form with no data displayed on it, then display a login screen on top of it. After correct login and password populate form with data. Thanks.
Hey, I used the following code, in a separate class which contains "sub main" (this you need to start application) I used it to show a loginform with behind it a background picture(frmbackground) after the login succeed I close all forms and call my application. Explanation by code 3 form's : Parent,Login,Background Friend Class AppMgr _ Shared Sub main() Dim frmbackground As New background Dim frmlogin As New Login frmbackground.Show() If frmlogin.ShowDialog = DialogResult.OK Then frmbackground.Close() Dim frmparent As New Parent Application.Run(frmparent) End If End Sub Maybe this is helpfull I listen, I learn, I deliver.
-
Is there an event that runs right after the form is displayed for the first time? I would like to show my form with no data displayed on it, then display a login screen on top of it. After correct login and password populate form with data. Thanks.
The Activated event is triggered after the load (and every time the form is activated) One can use a flag (to indicate first activation) and the activated event to solve the problem. class form inherits Windows.System.Forms.Form ... Private _firstActivation as boolean = true Private Sub frmMain_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated If (_firstActivation) Then _firstActivation = False Dim frm As New Login Dim res as DialogResult = frm.ShowDialog(me) ' Login Succeeded / Failed functionality End If End Sub ... end class hth, Q.
-
Is there an event that runs right after the form is displayed for the first time? I would like to show my form with no data displayed on it, then display a login screen on top of it. After correct login and password populate form with data. Thanks.
If you open your login screen like this: frmMain.Show 'Displays frmMain frmLogin.Show vbModal 'Displays Login form It should act like a message box, not allowing the user to access any other form. Hope this helps.