Results 1 to 5 of 5

Thread: passing control from one form to another

  1. #1

    Thread Starter
    Lively Member cageybee's Avatar
    Join Date
    Nov 2005
    Location
    Stanardsville, VA
    Posts
    81

    passing control from one form to another

    Problem I'm having is that i can pass control from one form to another when the user presses a button like:

    Private Sub Button2_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
    Me.Hide()
    Form3.Visible = True
    Form3.Focus()
    End Sub

    ...but, what if I want to pass control based on a timeout.....the following doesn't work (where sleep is a simple loop to pass time):

    Private Sub Form7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Me.Sleep(1000000)
    Form1.Visible = True
    Form1.Focus()

    End Sub

    any ideas?? (what I mean by doesn't work is that the displayed form doesn't change to the new form)

    thanks.

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: passing control from one form to another

    try calling the show() method of the form you want to display.

  3. #3

    Thread Starter
    Lively Member cageybee's Avatar
    Join Date
    Nov 2005
    Location
    Stanardsville, VA
    Posts
    81

    Re: passing control from one form to another

    nope....that still leaves the old form up there. The only way that (so far) I can get the new form to show is by using "me.close" which closes the old form and leaves the new form up there. The problem with that is that all the code in Form_load is executed before the loading form is visible.....argh.....so if me.close is in Form_load.....the form to load upon time-out is immediately shown and THEN the delay occurs instead of the other way around. It's like I need a way to execute code that is NOT in the Form_load routine.....so that the form can load...and then my code will execute.

    kgb
    Last edited by cageybee; Jul 28th, 2008 at 02:28 PM.

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: passing control from one form to another

    Quote Originally Posted by cageybee
    The problem with that is that all the code in Form_load is executed before the loading form is visible.....argh....

    kgb

    not if you put

    Code:
    me.visible = true
    application.doevents()
    in the form load before any other code.

  5. #5

    Thread Starter
    Lively Member cageybee's Avatar
    Join Date
    Nov 2005
    Location
    Stanardsville, VA
    Posts
    81

    Re: passing control from one form to another

    this is crazy....when I do this from within Private Sub Form7_Load Form:

    Form1.Visible = True
    Form1.Focus()
    Form1.Show()
    Application.DoEvents()
    MsgBox("test")

    it "shows" form1, but then after I hit <enter> it reshows form7.....

    form7 won't let go unless I hit the button and execute:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Me.Hide()
    Form1.Visible = True
    Form1.Focus()
    End Sub

    what is so special about code executed in the button_click????

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width