Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Event - After form is displayed for first time

Event - After form is displayed for first time

Scheduled Pinned Locked Moved Visual Basic
question
14 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dptalt
    wrote on last edited by
    #1

    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.

    T D A Q Q 5 Replies Last reply
    0
    • D dptalt

      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.

      T Offline
      T Offline
      Taen_Karth
      wrote on last edited by
      #2

      Yes Use the forms "OnLoad" event Just double click anywhere on your blank form in the IDE and it will send you to the "OnLoad" event for that form. Thanks, Taen Karth

      D 1 Reply Last reply
      0
      • T Taen_Karth

        Yes Use the forms "OnLoad" event Just double click anywhere on your blank form in the IDE and it will send you to the "OnLoad" event for that form. Thanks, Taen Karth

        D Offline
        D Offline
        dptalt
        wrote on last edited by
        #3

        The problem with the onload event is that it fires before the form is displayed. I want an event that fires right after the form is displayed for the first time.

        D 1 Reply Last reply
        0
        • D dptalt

          The problem with the onload event is that it fires before the form is displayed. I want an event that fires right after the form is displayed for the first time.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          There is no event that fires one-time only after the form is displayed. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          1 Reply Last reply
          0
          • D dptalt

            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.

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            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

            D 1 Reply Last reply
            0
            • D Dave Kreskowiak

              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

              D Offline
              D Offline
              dptalt
              wrote on last edited by
              #6

              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

              T R 2 Replies Last reply
              0
              • D dptalt

                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

                T Offline
                T Offline
                taenkarth
                wrote on last edited by
                #7

                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.

                D 1 Reply Last reply
                0
                • T taenkarth

                  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.

                  D Offline
                  D Offline
                  dptalt
                  wrote on last edited by
                  #8

                  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.

                  D 1 Reply Last reply
                  0
                  • D dptalt

                    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.

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #9

                    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

                    T 1 Reply Last reply
                    0
                    • D Dave Kreskowiak

                      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

                      T Offline
                      T Offline
                      Taen_Karth
                      wrote on last edited by
                      #10

                      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
                      
                      1 Reply Last reply
                      0
                      • D dptalt

                        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

                        R Offline
                        R Offline
                        Rizwan Bashir
                        wrote on last edited by
                        #11

                        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.

                        1 Reply Last reply
                        0
                        • D dptalt

                          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.

                          A Offline
                          A Offline
                          alwinSCH
                          wrote on last edited by
                          #12

                          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.

                          1 Reply Last reply
                          0
                          • D dptalt

                            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.

                            Q Offline
                            Q Offline
                            Qhalis
                            wrote on last edited by
                            #13

                            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.

                            1 Reply Last reply
                            0
                            • D dptalt

                              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.

                              Q Offline
                              Q Offline
                              quacks_a_lot
                              wrote on last edited by
                              #14

                              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.

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups