Loading a window on Button Click

How would I load a pre-existing window on button click

Thanks


Answer this question

Loading a window on Button Click

  • wakawaka54

    do you mean an existing form You would need to have a reference of it some place in order to access it.

    example, setting a property in Form2, to have a reference of the first form, Form1, will allow you to access it:

    Form2:

    Dim mainForm as Form1

    public property TheMainForm As Form1

    Get

    return Me.mainForm

    end get

    set(byval value as Form1)

    Me.mainForm = value

    end set

    end property

    ..

    ..

    'Button click event:

    if Me.mainForm is not nothing then

    Me.mainForm.Show() 'Or Focus() or BringToFront() or Visible = true

    end if

    from the first form:

    Dim theSecondForm as new Form2()

    theSecondForm.TheMainForm = Me

    theSecondForm.Show()

    you maybe best, depending on your application/situation, to use ShowDialog() to show a form, as it blocks the caller thread until the current form is closed, then it continues on running the previous form.

    is this what you are after



  • Blkbird

    excellent, glad I could help!

  • sticksnap

    Thanks that works

  • Loading a window on Button Click