Trouble with opening a new window

Recently I've been handed with a project that requires a window to open another window. The problem is that I can't find a way to open a new instance of itself. The client should click a button and a new window of itself should open up. Is there a way to accomplish such thing

Thanks



Answer this question

Trouble with opening a new window

  • Cecilia

    A form is a class with controls add's to it's controls collections. It can be reinstantiated any number of times.

    I'm not quite sure what you are referring to when you say windows

    I have a rich text box class Let's call it RTB. The class dynamically creates a rich textbox and the class also contains its events.

    dim a as new rtb....

    Dim tp as new tab page

    tp.controls .add(a)

    tabc.controls.add(tp) ' Add a new tabpage to a tabcontrol

    and there you are......



  • GBez

    cgraus wrote:

    Actually, you should either make the form instance a member variable, or call ShowDialog to show a modal form.

    I very much doubt that any form is going to show another instance of the same type as a modal dialogue. Sounds like a form containing a document or maybe MDI siblings to me.

  • Buck Ryan

    Hi JinMaster,
    Try this:

    Assuming you have two forms(windows) called Form1 and Form2. Form 1 being you main form:

    Set the following properties:
    IsMdiContainer to True
    WindowState to Maximised

    Place this code globally

    Dim myNewForm As New Form 2

    Place this code inside the subroutine (procedure) as attached to an interface object (ie a button etc)

    myNewForm.ShowDialog()

    That should do it - if you want to use variables that you have declared in Form2 in Form1, use:

    myNewForm.Form2Variable

    Form2Variable is any variable in Form2

    Hope this works - aande2003


  • Russ2

    To create and display an instance of a form you do this:

    Dim f As New Form

    f.Show()

    It doesn't matter where you want to do it from, that's how you do it. Just substitute the appropriate class name for "Form".


  • GeneQ

    Perhaps, but as a generic piece of advice, it should be a member, or modal.



  • sianan

    I have to point out here that the original question says nothing about MDI or dialogues. The question is how would a form open a second instance of the same type. I think it unlikely that any form is going to open a second instance of its own type as a modal dialogue. Also, the advice about using a member variable is a generalisation that has nothing to do with the question either. You would use a member variable if you require the functionality that a member variable provides, i.e. the object can be accessed via that reference throughout the class. If you don't require access to the form outside the method in which it is created then using a member variable serves no purpose and actually goes against the idea of keeping the scope of every variable as narrow as possible.
  • jeff2

    Actually, you should either make the form instance a member variable, or call ShowDialog to show a modal form.



  • Sebastian Salgado

    >>If you don't require access to the form outside the method in which it is created then using a member variable serves no purpose and actually goes against the idea of keeping the scope of every variable as narrow as possible.

    True. But if you create a dialog and show it, then to not store a reference to the dialog would be a long way from any sort of best practice. I'm sure that in .NET, unlike C++, it would work. It still makes more sense to have a reference to the object you create, it would be rare to create a dialog and never want to interact with it again, especially a modeless one.



  • RonMoreno

    The previous example given shows dialog interaction - you wouldn't interact with a copy of the same form Hence the variable scoping example given.

    Simply opening a nonmodal form would be the answer.

    This opens a nonmodal form of itself:

    Dim childForm As New Form1

    childForm.Show()


  • Trouble with opening a new window